diff --git a/README.md b/README.md index 4c51613..6c21ced 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,12 @@ tarpc = { git = "https://github.com/google/tarpc" } tarpc-plugins = { git = "https://github.com/google/tarpc" } ``` -## Example -```rust +## Example: Sync + +tarpc has two APIs: `sync` for blocking requests and `future` for asynchronous +requests. Here's how to use the sync api. + +```rust,no_run // required by `FutureClient` (not used directly in this example) #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] @@ -53,7 +57,7 @@ extern crate tarpc; extern crate tokio_core; use tarpc::{client, server}; -use tarpc::client::sync::Connect; +use tarpc::client::sync::ClientExt; use tarpc::util::{FirstSocketAddr, Never}; service! { @@ -92,7 +96,7 @@ races! See the `tarpc_examples` package for more examples. Here's the same service, implemented using futures. -```rust +```rust,no_run #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] @@ -162,7 +166,7 @@ Both TLS streams and TCP streams are supported in the same binary when the `tls` However, if you are working with both stream types, ensure that you use the TLS clients with TLS servers and TCP clients with TCP servers. -```rust +```rust,no_run #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] @@ -188,7 +192,7 @@ struct HelloServer; impl FutureService for HelloServer { type HelloFut = Result; - fn hello(&mut self, name: String) -> Self::HelloFut { + fn hello(&self, name: String) -> Self::HelloFut { Ok(format!("Hello, {}!", name)) } } @@ -208,7 +212,7 @@ fn main() { .unwrap(); let options = client::Options::default() .handle(reactor.handle()) - .tls(client::tls::Context::new("foobar.com").unwrap())); + .tls(client::tls::Context::new("foobar.com").unwrap()); reactor.run(FutureClient::connect(addr, options) .map_err(tarpc::Error::from) .and_then(|client| client.hello("Mom".to_string())) @@ -235,7 +239,7 @@ E>`. The error type defaults to `tarpc::util::Never` (a wrapper for `!` which im `std::error::Error`) if no error type is explicitly specified in the `service!` macro invocation. An error type can be specified like so: -```rust +```rust,ignore use tarpc::util::Message; service! { @@ -251,23 +255,19 @@ the macro automatically chooses `tarpc::util::Never` as the error type. The above declaration would produce the following synchronous service trait: -```rust -impl SyncService for HelloServer { - fn hello(&self, name: String) -> Result { - Ok(format!("Hello, {}!", name)) - } +```rust,ignore +trait SyncService { + fn hello(&self, name: String) -> Result; } ``` and the following future-based trait: -```rust -impl FutureService for HelloServer { - type HelloFut = Result; +```rust,ignore +trait FutureService for HelloServer { + type HelloFut = IntoFutue; - fn hello(&mut self, name: String) -> Self::HelloFut { - Ok(format!("Hello, {}!", name)) - } + fn hello(&mut self, name: String) -> Self::HelloFut; } ``` diff --git a/hooks/pre-push b/hooks/pre-push index b3ddbfe..c156b77 100755 --- a/hooks/pre-push +++ b/hooks/pre-push @@ -123,7 +123,7 @@ else printf "${SUCCESS}\n" fi - run_cargo build + run_cargo build run_cargo test fi