Skip to content

Commit 2358986

Browse files
committed
Update README for latest version
1 parent 160b561 commit 2358986

File tree

5 files changed

+20
-65
lines changed

5 files changed

+20
-65
lines changed

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ your `Cargo.toml`:
8282
```toml
8383
anyhow = "1.0"
8484
futures = "0.3"
85-
tarpc = { version = "0.31", features = ["tokio1"] }
85+
tarpc = { version = "0.34", features = ["tokio1"] }
8686
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
8787
```
8888

@@ -93,7 +93,6 @@ For a more real-world example, see [example-service](example-service).
9393
First, let's set up the dependencies and service definition.
9494

9595
```rust
96-
use futures::future::{self, Ready};
9796
use tarpc::{
9897
client, context,
9998
server::{self, Channel},
@@ -135,11 +134,16 @@ async fn main() -> anyhow::Result<()> {
135134
let (client_transport, server_transport) = tarpc::transport::channel::unbounded();
136135

137136
let server = server::BaseChannel::with_defaults(server_transport);
138-
tokio::spawn(server.execute(HelloServer.serve()));
137+
tokio::spawn(
138+
server.execute(HelloServer.serve())
139+
// Handle all requests concurrently.
140+
.for_each(|response| async move {
141+
tokio::spawn(response);
142+
}));
139143

140144
// WorldClient is generated by the #[tarpc::service] attribute. It has a constructor `new`
141145
// that takes a config and any Transport as input.
142-
let client = WorldClient::new(client::Config::default(), client_transport).spawn();
146+
let mut client = WorldClient::new(client::Config::default(), client_transport).spawn();
143147

144148
// The client has an RPC method for each RPC defined in the annotated trait. It takes the same
145149
// args as defined, with the addition of a Context, which is always the first arg. The Context

tarpc/src/client.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ mod tests {
11411141

11421142
trait PollTest {
11431143
type T;
1144-
fn unwrap(self) -> Poll<Self::T>;
11451144
fn ready(self) -> Self::T;
11461145
}
11471146

@@ -1151,15 +1150,6 @@ mod tests {
11511150
{
11521151
type T = Option<T>;
11531152

1154-
fn unwrap(self) -> Poll<Option<T>> {
1155-
match self {
1156-
Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(t)),
1157-
Poll::Ready(None) => Poll::Ready(None),
1158-
Poll::Ready(Some(Err(e))) => panic!("{}", e.to_string()),
1159-
Poll::Pending => Poll::Pending,
1160-
}
1161-
}
1162-
11631153
fn ready(self) -> Option<T> {
11641154
match self {
11651155
Poll::Ready(Some(Ok(t))) => Some(t),

tarpc/src/lib.rs

+4-40
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
//! Add to your `Cargo.toml` dependencies:
5555
//!
5656
//! ```toml
57-
//! tarpc = "0.29"
57+
//! tarpc = "0.34"
5858
//! ```
5959
//!
6060
//! The `tarpc::service` attribute expands to a collection of items that form an rpc service.
@@ -69,7 +69,7 @@
6969
//! ```toml
7070
//! anyhow = "1.0"
7171
//! futures = "0.3"
72-
//! tarpc = { version = "0.29", features = ["tokio1"] }
72+
//! tarpc = { version = "0.34", features = ["tokio1"] }
7373
//! tokio = { version = "1.0", features = ["macros"] }
7474
//! ```
7575
//!
@@ -83,7 +83,6 @@
8383
//! # extern crate futures;
8484
//!
8585
//! use futures::{
86-
//! future::{self, Ready},
8786
//! prelude::*,
8887
//! };
8988
//! use tarpc::{
@@ -106,7 +105,6 @@
106105
//! ```rust
107106
//! # extern crate futures;
108107
//! # use futures::{
109-
//! # future::{self, Ready},
110108
//! # prelude::*,
111109
//! # };
112110
//! # use tarpc::{
@@ -141,7 +139,6 @@
141139
//! ```rust
142140
//! # extern crate futures;
143141
//! # use futures::{
144-
//! # future::{self, Ready},
145142
//! # prelude::*,
146143
//! # };
147144
//! # use tarpc::{
@@ -253,9 +250,7 @@ pub(crate) mod util;
253250

254251
pub use crate::transport::sealed::Transport;
255252

256-
use anyhow::Context as _;
257-
use futures::task::*;
258-
use std::{any::Any, error::Error, fmt::Display, io, sync::Arc, time::Instant};
253+
use std::{any::Any, error::Error, io, sync::Arc, time::Instant};
259254

260255
/// A message from a client to a server.
261256
#[derive(Debug)]
@@ -504,37 +499,6 @@ impl<T> Request<T> {
504499
}
505500
}
506501

507-
pub(crate) trait PollContext<T> {
508-
fn context<C>(self, context: C) -> Poll<Option<anyhow::Result<T>>>
509-
where
510-
C: Display + Send + Sync + 'static;
511-
512-
fn with_context<C, F>(self, f: F) -> Poll<Option<anyhow::Result<T>>>
513-
where
514-
C: Display + Send + Sync + 'static,
515-
F: FnOnce() -> C;
516-
}
517-
518-
impl<T, E> PollContext<T> for Poll<Option<Result<T, E>>>
519-
where
520-
E: Error + Send + Sync + 'static,
521-
{
522-
fn context<C>(self, context: C) -> Poll<Option<anyhow::Result<T>>>
523-
where
524-
C: Display + Send + Sync + 'static,
525-
{
526-
self.map(|o| o.map(|r| r.context(context)))
527-
}
528-
529-
fn with_context<C, F>(self, f: F) -> Poll<Option<anyhow::Result<T>>>
530-
where
531-
C: Display + Send + Sync + 'static,
532-
F: FnOnce() -> C,
533-
{
534-
self.map(|o| o.map(|r| r.with_context(f)))
535-
}
536-
}
537-
538502
#[test]
539503
fn test_channel_any_casts() {
540504
use assert_matches::assert_matches;
@@ -566,7 +530,7 @@ fn test_channel_error_upcast() {
566530

567531
#[derive(Debug)]
568532
struct E;
569-
impl Display for E {
533+
impl fmt::Display for E {
570534
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
571535
write!(f, "E")
572536
}

tarpc/tests/compile_fail/serde1/opt_out_serde.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ error[E0277]: the trait bound `FooRequest: Serialize` is not satisfied
77
| required by a bound introduced by this call
88
|
99
= help: the following other types implement trait `Serialize`:
10-
bool
11-
char
12-
isize
13-
i8
14-
i16
15-
i32
16-
i64
17-
i128
10+
&'a T
11+
&'a mut T
12+
()
13+
(T0, T1)
14+
(T0, T1, T2)
15+
(T0, T1, T2, T3)
16+
(T0, T1, T2, T3, T4)
17+
(T0, T1, T2, T3, T4, T5)
1818
and $N others

tarpc/tests/service_functional.rs

-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ async fn dropped_channel_aborts_in_flight_requests() -> anyhow::Result<()> {
5454
#[derive(Clone)]
5555
struct LoopServer;
5656

57-
#[derive(Debug)]
58-
struct AllHandlersComplete;
59-
6057
impl Loop for LoopServer {
6158
async fn r#loop(self, _: context::Context) {
6259
loop {

0 commit comments

Comments
 (0)