Struct toy_rpc::client::async_std::Client[][src]

pub struct Client<Mode> { /* fields omitted */ }

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]

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]

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]

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]

impl<Mode> Sync for Client<Mode> where
    Mode: Sync
[src]

impl<Mode> Unpin for Client<Mode> where
    Mode: Unpin
[src]

impl<Mode> !UnwindSafe for Client<Mode>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,