mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-05 11:06:11 +01:00
Fix readme for real this time.
This commit is contained in:
38
README.md
38
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<String, Never>;
|
||||
|
||||
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<String, Message> {
|
||||
Ok(format!("Hello, {}!", name))
|
||||
}
|
||||
```rust,ignore
|
||||
trait SyncService {
|
||||
fn hello(&self, name: String) -> Result<String, Message>;
|
||||
}
|
||||
```
|
||||
|
||||
and the following future-based trait:
|
||||
|
||||
```rust
|
||||
impl FutureService for HelloServer {
|
||||
type HelloFut = Result<String, Message>;
|
||||
```rust,ignore
|
||||
trait FutureService for HelloServer {
|
||||
type HelloFut = IntoFutue<String, Message>;
|
||||
|
||||
fn hello(&mut self, name: String) -> Self::HelloFut {
|
||||
Ok(format!("Hello, {}!", name))
|
||||
}
|
||||
fn hello(&mut self, name: String) -> Self::HelloFut;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ else
|
||||
printf "${SUCCESS}\n"
|
||||
fi
|
||||
|
||||
run_cargo build
|
||||
run_cargo build
|
||||
run_cargo test
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user