Skip to content

Commit

Permalink
Update README for latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
tikue committed Jun 29, 2024
1 parent 160b561 commit 2358986
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 65 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ your `Cargo.toml`:
```toml
anyhow = "1.0"
futures = "0.3"
tarpc = { version = "0.31", features = ["tokio1"] }
tarpc = { version = "0.34", features = ["tokio1"] }
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
```

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

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

let server = server::BaseChannel::with_defaults(server_transport);
tokio::spawn(server.execute(HelloServer.serve()));
tokio::spawn(
server.execute(HelloServer.serve())
// Handle all requests concurrently.
.for_each(|response| async move {
tokio::spawn(response);
}));

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

// The client has an RPC method for each RPC defined in the annotated trait. It takes the same
// args as defined, with the addition of a Context, which is always the first arg. The Context
Expand Down
10 changes: 0 additions & 10 deletions tarpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,6 @@ mod tests {

trait PollTest {
type T;
fn unwrap(self) -> Poll<Self::T>;
fn ready(self) -> Self::T;
}

Expand All @@ -1151,15 +1150,6 @@ mod tests {
{
type T = Option<T>;

fn unwrap(self) -> Poll<Option<T>> {
match self {
Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(t)),
Poll::Ready(None) => Poll::Ready(None),
Poll::Ready(Some(Err(e))) => panic!("{}", e.to_string()),
Poll::Pending => Poll::Pending,
}
}

fn ready(self) -> Option<T> {
match self {
Poll::Ready(Some(Ok(t))) => Some(t),
Expand Down
44 changes: 4 additions & 40 deletions tarpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
//! Add to your `Cargo.toml` dependencies:
//!
//! ```toml
//! tarpc = "0.29"
//! tarpc = "0.34"
//! ```
//!
//! The `tarpc::service` attribute expands to a collection of items that form an rpc service.
Expand All @@ -69,7 +69,7 @@
//! ```toml
//! anyhow = "1.0"
//! futures = "0.3"
//! tarpc = { version = "0.29", features = ["tokio1"] }
//! tarpc = { version = "0.34", features = ["tokio1"] }
//! tokio = { version = "1.0", features = ["macros"] }
//! ```
//!
Expand All @@ -83,7 +83,6 @@
//! # extern crate futures;
//!
//! use futures::{
//! future::{self, Ready},
//! prelude::*,
//! };
//! use tarpc::{
Expand All @@ -106,7 +105,6 @@
//! ```rust
//! # extern crate futures;
//! # use futures::{
//! # future::{self, Ready},
//! # prelude::*,
//! # };
//! # use tarpc::{
Expand Down Expand Up @@ -141,7 +139,6 @@
//! ```rust
//! # extern crate futures;
//! # use futures::{
//! # future::{self, Ready},
//! # prelude::*,
//! # };
//! # use tarpc::{
Expand Down Expand Up @@ -253,9 +250,7 @@ pub(crate) mod util;

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

use anyhow::Context as _;
use futures::task::*;
use std::{any::Any, error::Error, fmt::Display, io, sync::Arc, time::Instant};
use std::{any::Any, error::Error, io, sync::Arc, time::Instant};

/// A message from a client to a server.
#[derive(Debug)]
Expand Down Expand Up @@ -504,37 +499,6 @@ impl<T> Request<T> {
}
}

pub(crate) trait PollContext<T> {
fn context<C>(self, context: C) -> Poll<Option<anyhow::Result<T>>>
where
C: Display + Send + Sync + 'static;

fn with_context<C, F>(self, f: F) -> Poll<Option<anyhow::Result<T>>>
where
C: Display + Send + Sync + 'static,
F: FnOnce() -> C;
}

impl<T, E> PollContext<T> for Poll<Option<Result<T, E>>>
where
E: Error + Send + Sync + 'static,
{
fn context<C>(self, context: C) -> Poll<Option<anyhow::Result<T>>>
where
C: Display + Send + Sync + 'static,
{
self.map(|o| o.map(|r| r.context(context)))
}

fn with_context<C, F>(self, f: F) -> Poll<Option<anyhow::Result<T>>>
where
C: Display + Send + Sync + 'static,
F: FnOnce() -> C,
{
self.map(|o| o.map(|r| r.with_context(f)))
}
}

#[test]
fn test_channel_any_casts() {
use assert_matches::assert_matches;
Expand Down Expand Up @@ -566,7 +530,7 @@ fn test_channel_error_upcast() {

#[derive(Debug)]
struct E;
impl Display for E {
impl fmt::Display for E {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "E")
}
Expand Down
16 changes: 8 additions & 8 deletions tarpc/tests/compile_fail/serde1/opt_out_serde.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ error[E0277]: the trait bound `FooRequest: Serialize` is not satisfied
| required by a bound introduced by this call
|
= help: the following other types implement trait `Serialize`:
bool
char
isize
i8
i16
i32
i64
i128
&'a T
&'a mut T
()
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
(T0, T1, T2, T3, T4, T5)
and $N others
3 changes: 0 additions & 3 deletions tarpc/tests/service_functional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ async fn dropped_channel_aborts_in_flight_requests() -> anyhow::Result<()> {
#[derive(Clone)]
struct LoopServer;

#[derive(Debug)]
struct AllHandlersComplete;

impl Loop for LoopServer {
async fn r#loop(self, _: context::Context) {
loop {
Expand Down

0 comments on commit 2358986

Please sign in to comment.