Remove serde_transport::tcp::connect_with.

Instead, serde_transport::tcp::connect returns a future named Connect
that has methods to directly access the framing config. This is
consistent with how serde_transport::tcp::listen returns a future with
methods to access the framing config. In addition to this consistency,
it reduces the API surface and provides a simpler user transition from
"zero config" to "some config".
This commit is contained in:
Tim Kuehn
2020-08-19 17:51:53 -07:00
parent 3207affb4a
commit 2264ebecfc
2 changed files with 46 additions and 26 deletions

View File

@@ -7,9 +7,7 @@
use clap::{App, Arg};
use std::{io, net::SocketAddr};
use tarpc::{client, context};
use tokio::net::TcpStream;
use tokio_serde::formats::Json;
use tokio_util::codec::LengthDelimitedCodec;
#[tokio::main]
async fn main() -> io::Result<()> {
@@ -45,17 +43,13 @@ async fn main() -> io::Result<()> {
let name = flags.value_of("name").unwrap().into();
let conn = TcpStream::connect(server_addr).await?;
let transport = tarpc::serde_transport::new(
LengthDelimitedCodec::builder()
.max_frame_length(4294967296)
.new_framed(conn),
Json::default(),
);
let mut transport = tarpc::serde_transport::tcp::connect(server_addr, Json::default);
transport.config_mut().max_frame_length(4294967296);
// WorldClient is generated by the service attribute. It has a constructor `new` that takes a
// config and any Transport as input.
let mut client = service::WorldClient::new(client::Config::default(), transport).spawn()?;
let mut client =
service::WorldClient::new(client::Config::default(), transport.await?).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