Struct toy_rpc::client::async_std::Client [−][src]
RPC Client. Unlike Server
, the Client
struct contains field that uses runtime dependent synchronization primitives,
thus there is a separate 'Client' struct defined for each of the async-std
and tokio
runtime.
Implementations
impl Client<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 in a blocking manner.
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; #[async_std::main] async fn main() { let addr = "127.0.0.1:8080"; 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:8080"; 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 toy_rpc::Client; use toy_rpc::error::Error; #[async_std::main] async fn main() { let addr = "127.0.0.1:8080"; 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); }
pub async fn close(self)
[src]
Gracefully shutdown the connection.
For a WebSocket connection, a Close message will be sent. For a raw TCP connection, the client will simply drop the connection
Auto Trait Implementations
impl<Mode> !RefUnwindSafe for Client<Mode>
[src]
impl<Mode> Send for Client<Mode> where
Mode: Send,
[src]
Mode: Send,
impl<Mode> Sync for Client<Mode> where
Mode: Sync,
[src]
Mode: Sync,
impl<Mode> Unpin for Client<Mode> where
Mode: Unpin,
[src]
Mode: Unpin,
impl<Mode> !UnwindSafe for Client<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>,