mirror of
https://github.com/OMGeeky/tarpc.git
synced 2025-12-28 07:12:05 +01:00
Run cargo fmt
This commit is contained in:
@@ -7,9 +7,9 @@
|
|||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use std::{io, net::SocketAddr};
|
use std::{io, net::SocketAddr};
|
||||||
use tarpc::{client, context};
|
use tarpc::{client, context};
|
||||||
|
use tokio::net::TcpStream;
|
||||||
use tokio_serde::formats::Json;
|
use tokio_serde::formats::Json;
|
||||||
use tokio_util::codec::LengthDelimitedCodec;
|
use tokio_util::codec::LengthDelimitedCodec;
|
||||||
use tokio::net::TcpStream;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
@@ -47,11 +47,12 @@ async fn main() -> io::Result<()> {
|
|||||||
|
|
||||||
let conn = TcpStream::connect(server_addr).await?;
|
let conn = TcpStream::connect(server_addr).await?;
|
||||||
let transport = tarpc::serde_transport::new(
|
let transport = tarpc::serde_transport::new(
|
||||||
LengthDelimitedCodec::builder().max_frame_length(4294967296).new_framed(conn),
|
LengthDelimitedCodec::builder()
|
||||||
|
.max_frame_length(4294967296)
|
||||||
|
.new_framed(conn),
|
||||||
Json::default(),
|
Json::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// WorldClient is generated by the service attribute. It has a constructor `new` that takes a
|
// WorldClient is generated by the service attribute. It has a constructor `new` that takes a
|
||||||
// config and any Transport as input.
|
// 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).spawn()?;
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{error::Error, io, pin::Pin};
|
use std::{error::Error, io, pin::Pin};
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_serde::{Framed as SerdeFramed, *};
|
use tokio_serde::{Framed as SerdeFramed, *};
|
||||||
use tokio_util::codec::{length_delimited::{self, LengthDelimitedCodec}, Framed};
|
use tokio_util::codec::{
|
||||||
|
length_delimited::{self, LengthDelimitedCodec},
|
||||||
|
Framed,
|
||||||
|
};
|
||||||
|
|
||||||
/// A transport that serializes to, and deserializes from, a byte stream.
|
/// A transport that serializes to, and deserializes from, a byte stream.
|
||||||
#[pin_project]
|
#[pin_project]
|
||||||
@@ -91,8 +94,10 @@ fn convert<E: Into<Box<dyn Error + Send + Sync>>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a new transport from a framed transport and a serialization codec.
|
/// Constructs a new transport from a framed transport and a serialization codec.
|
||||||
pub fn new<S, Item, SinkItem, Codec>(framed_io: Framed<S, LengthDelimitedCodec>, codec: Codec)
|
pub fn new<S, Item, SinkItem, Codec>(
|
||||||
-> Transport<S, Item, SinkItem, Codec>
|
framed_io: Framed<S, LengthDelimitedCodec>,
|
||||||
|
codec: Codec,
|
||||||
|
) -> Transport<S, Item, SinkItem, Codec>
|
||||||
where
|
where
|
||||||
S: AsyncWrite + AsyncRead,
|
S: AsyncWrite + AsyncRead,
|
||||||
Item: for<'de> Deserialize<'de>,
|
Item: for<'de> Deserialize<'de>,
|
||||||
@@ -158,7 +163,10 @@ pub mod tcp {
|
|||||||
SinkItem: Serialize,
|
SinkItem: Serialize,
|
||||||
Codec: Serializer<SinkItem> + Deserializer<Item>,
|
Codec: Serializer<SinkItem> + Deserializer<Item>,
|
||||||
{
|
{
|
||||||
Ok(new(Framed::new(TcpStream::connect(addr).await?, config), codec))
|
Ok(new(
|
||||||
|
Framed::new(TcpStream::connect(addr).await?, config),
|
||||||
|
codec,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connects to `addr`, wrapping the connection in a JSON transport.
|
/// Connects to `addr`, wrapping the connection in a JSON transport.
|
||||||
|
|||||||
Reference in New Issue
Block a user