Struct toy_rpc::client::Client [−][src]
RPC Client
Implementations
impl Client<Arc<Mutex<Box<dyn ClientCodec>>>, NotConnected>
[src]
The following impl block is controlled by feature flag. It is enabled if and only if exactly one of the the following feature flag is turned on
serde_bincode
serde_json
serde_cbor
serde_rmp
pub fn with_stream(
stream: TcpStream
) -> Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>
[src]
stream: TcpStream
) -> Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>
Creates an RPC Client
over socket with a specified async_std::net::TcpStream
and the default codec
This is enabled if and only if exactly one of the the following feature flag is turned on
serde_bincode
serde_json
serde_cbor
serde_rmp
Example
use async_std::net::TcpStream; #[async_std::main] async fn main() { let stream = TcpStream::connect("127.0.0.1:8888").await.unwrap(); let client = Client::with_stream(stream); }
pub async fn dial(
addr: impl ToSocketAddrs
) -> Result<Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>, Error>
[src]
addr: impl ToSocketAddrs
) -> Result<Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>, Error>
Connects the an RPC server over socket at the specified network address
This is enabled if and only if exactly one of the the following feature flag is turned on
serde_bincode
serde_json
serde_cbor
serde_rmp
Example
use toy_rpc::Client; #[async_std::main] async fn main() { let addr = "127.0.0.1"; let client = Client::dial(addr).await; }
impl Client<Arc<Mutex<Box<dyn ClientCodec>>>, NotConnected>
[src]
pub fn with_codec<C>(
codec: C
) -> Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected> where
C: ClientCodec + Send + Sync + 'static,
[src]
codec: C
) -> Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected> where
C: ClientCodec + Send + Sync + 'static,
Creates an RPC 'Client` over socket with a specified codec
Example
use async_std::net::TcpStream; use toy_rpc::codec::bincode::Codec; use toy_rpc::Client; #[async_std::main] async fn main() { let addr = "127.0.0.1:8888"; let stream = TcpStream::connect(addr).await.unwrap(); let codec = Codec::new(stream); let client = Client::with_codec(codec); }
impl Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>
[src]
pub fn call<Req, Res>(
&self,
service_method: impl ToString,
args: Req
) -> Result<Res, Error> where
Req: Serialize + Send + Sync,
Res: DeserializeOwned,
[src]
&self,
service_method: impl ToString,
args: Req
) -> Result<Res, Error> where
Req: Serialize + Send + Sync,
Res: DeserializeOwned,
Invokes the named function and wait synchronously
This function internally calls task::block_on
to wait for the response.
Do NOT use this function inside another task::block_on
.async_std
Example
use toy_rpc::client::Client; use toy_rpc::error::Error; #[async_std::main] async fn main() { let addr = "127.0.0.1:8888"; let client = Client::dial(addr).await.unwrap(); let args = "arguments"; let reply: Result<String, Error> = client.call("echo_service.echo", &args); println!("{:?}", reply); }
pub fn spawn_task<Req, Res>(
&self,
service_method: impl ToString + Send + 'static,
args: Req
) -> JoinHandle<Result<Res, Error>> where
Req: Serialize + Send + Sync + 'static,
Res: DeserializeOwned + Send + 'static,
[src]
&self,
service_method: impl ToString + Send + 'static,
args: Req
) -> JoinHandle<Result<Res, Error>> where
Req: Serialize + Send + Sync + 'static,
Res: DeserializeOwned + Send + 'static,
Invokes the named function asynchronously by spawning a new task and returns the JoinHandle
use async_std::task; use toy_rpc::client::Client; use toy_rpc::error::Error; #[async_std::main] async fn main() { let addr = "127.0.0.1:8888"; let client = Client::dial(addr).await.unwrap(); let args = "arguments"; let handle: task::JoinHandle<Result<Res, Error>> = client.spawn_task("echo_service.echo", args); let reply: Result<String, Error> = handle.await; println!("{:?}", reply); }
pub async fn async_call<Req, Res>(
&self,
service_method: impl ToString,
args: Req
) -> Result<Res, Error> where
Req: Serialize + Send + Sync,
Res: DeserializeOwned,
[src]
&self,
service_method: impl ToString,
args: Req
) -> Result<Res, Error> where
Req: Serialize + Send + Sync,
Res: DeserializeOwned,
Invokes the named function asynchronously
Example
use async_std::task; use toy_rpc::client::Client; use toy_rpc::error::Error; #[async_std::main] async fn main() { let addr = "127.0.0.1:8888"; let client = Client::dial(addr).await.unwrap(); let args = "arguments"; let reply: Result<String, Error> = client.async_call("echo_service.echo", &args).await; println!("{:?}", reply); }
impl Client<Arc<Mutex<Box<dyn ClientCodec>>>, NotConnected>
[src]
The following impl block is controlled by feature flag. It is enabled if and only if exactly one of the the following feature flag is turned on
serde_bincode
serde_json
serde_cbor
serde_rmp
pub async fn dial_http(
addr: &'static str
) -> Result<Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>, Error>
[src]
addr: &'static str
) -> Result<Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>, Error>
Connects to an HTTP RPC server at the specified network address using the defatul codec
If a network path were to be supplpied, the network path must end with a slash "/"
This is enabled if and only if exactly one of the the following feature flag is turned on
serde_bincode
serde_json
serde_cbor
serde_rmp
Example
use toy_rpc::client::Client; use toy_rpc::error::Error; #[async_std::main] async fn main() { let addr = "http://127.0.0.1:8888/rpc/"; let client = Client::dial_http(addr).await.unwrap(); }
TODO: check if the path ends with a slash TODO: try send and recv trait object
pub async fn dial_websocket(
addr: &'static str
) -> Result<Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>, Error>
[src]
addr: &'static str
) -> Result<Client<Arc<Mutex<Box<dyn ClientCodec>>>, Connected>, Error>
Auto Trait Implementations
impl<T, Mode> !RefUnwindSafe for Client<T, Mode>
[src]
impl<T, Mode> Send for Client<T, Mode> where
Mode: Send,
T: Send,
[src]
Mode: Send,
T: Send,
impl<T, Mode> Sync for Client<T, Mode> where
Mode: Sync,
T: Sync,
[src]
Mode: Sync,
T: Sync,
impl<T, Mode> Unpin for Client<T, Mode> where
Mode: Unpin,
T: Unpin,
[src]
Mode: Unpin,
T: Unpin,
impl<T, Mode> !UnwindSafe for Client<T, Mode>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,