Skip to content

Commit 444a490

Browse files
committed
example: update to match new ttrpc-compiler
update for commit 1f2a26 Signed-off-by: Tim Zhang <tim@hyper.sh>
1 parent 1f2a266 commit 444a490

File tree

7 files changed

+13
-26
lines changed

7 files changed

+13
-26
lines changed

example/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ path = "./async-stream-client.rs"
5151

5252
[build-dependencies]
5353
ttrpc-codegen = { path = "../ttrpc-codegen"}
54+
55+
[patch.crates-io]
56+
ttrpc-compiler = { path = "../compiler"}
57+

example/async-client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
mod protocols;
77
mod utils;
88
#[cfg(unix)]
9-
use protocols::r#async::{agent, agent_ttrpc, health, health_ttrpc};
9+
use protocols::asynchronous::{agent, agent_ttrpc, health, health_ttrpc};
1010
use ttrpc::context::{self, Context};
1111
#[cfg(unix)]
1212
use ttrpc::r#async::Client;

example/async-server.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::sync::Arc;
1414
use log::LevelFilter;
1515

1616
#[cfg(unix)]
17-
use protocols::r#async::{agent, agent_ttrpc, health, health_ttrpc, types};
17+
use protocols::asynchronous::{agent, agent_ttrpc, health, health_ttrpc, types};
1818
#[cfg(unix)]
1919
use ttrpc::asynchronous::Server;
2020
use ttrpc::error::{Error, Result};
@@ -97,13 +97,8 @@ fn main() {
9797
async fn main() {
9898
simple_logging::log_to_stderr(LevelFilter::Trace);
9999

100-
let h = Box::new(HealthService {}) as Box<dyn health_ttrpc::Health + Send + Sync>;
101-
let h = Arc::new(h);
102-
let hservice = health_ttrpc::create_health(h);
103-
104-
let a = Box::new(AgentService {}) as Box<dyn agent_ttrpc::AgentService + Send + Sync>;
105-
let a = Arc::new(a);
106-
let aservice = agent_ttrpc::create_agent_service(a);
100+
let hservice = health_ttrpc::create_health(Arc::new(HealthService {}));
101+
let aservice = agent_ttrpc::create_agent_service(Arc::new(AgentService {}));
107102

108103
utils::remove_if_sock_exist(utils::SOCK_ADDR).unwrap();
109104

example/async-stream-client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
mod protocols;
77
mod utils;
88
#[cfg(unix)]
9-
use protocols::r#async::{empty, streaming, streaming_ttrpc};
9+
use protocols::asynchronous::{empty, streaming, streaming_ttrpc};
1010
use ttrpc::context::{self, Context};
1111
#[cfg(unix)]
1212
use ttrpc::r#async::Client;

example/async-stream-server.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::sync::Arc;
1111
use log::{info, LevelFilter};
1212

1313
#[cfg(unix)]
14-
use protocols::r#async::{empty, streaming, streaming_ttrpc};
14+
use protocols::asynchronous::{empty, streaming, streaming_ttrpc};
1515
#[cfg(unix)]
1616
use ttrpc::{asynchronous::Server, Error};
1717

@@ -163,11 +163,7 @@ fn main() {
163163
#[tokio::main(flavor = "current_thread")]
164164
async fn main() {
165165
simple_logging::log_to_stderr(LevelFilter::Info);
166-
167-
let s = Box::new(StreamingService {}) as Box<dyn streaming_ttrpc::Streaming + Send + Sync>;
168-
let s = Arc::new(s);
169-
let service = streaming_ttrpc::create_streaming(s);
170-
166+
let service = streaming_ttrpc::create_streaming(Arc::new(StreamingService {}));
171167
utils::remove_if_sock_exist(utils::SOCK_ADDR).unwrap();
172168

173169
let mut server = Server::new()

example/protocols/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
//
55
#[cfg(unix)]
66
pub mod asynchronous;
7-
#[cfg(unix)]
8-
pub use asynchronous as r#async;
97
pub mod sync;

example/server.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,8 @@ impl agent_ttrpc::AgentService for AgentService {
8181

8282
fn main() {
8383
simple_logging::log_to_stderr(LevelFilter::Trace);
84-
85-
let h = Box::new(HealthService {}) as Box<dyn health_ttrpc::Health + Send + Sync>;
86-
let h = Arc::new(h);
87-
let hservice = health_ttrpc::create_health(h);
88-
89-
let a = Box::new(AgentService {}) as Box<dyn agent_ttrpc::AgentService + Send + Sync>;
90-
let a = Arc::new(a);
91-
let aservice = agent_ttrpc::create_agent_service(a);
84+
let hservice = health_ttrpc::create_health(Arc::new(HealthService {}));
85+
let aservice = agent_ttrpc::create_agent_service(Arc::new(AgentService {}));
9286

9387
utils::remove_if_sock_exist(utils::SOCK_ADDR).unwrap();
9488
let mut server = Server::new()

0 commit comments

Comments
 (0)