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<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(addr: impl ToSocketAddrs) -> Result<Client<Connected>, Error>
[src]
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:8080"; let client = Client::dial(addr).await; }
pub async fn dial_websocket(addr: &str) -> Result<Client<Connected>, Error>
[src]
Similar to dial
, this connects to an WebSocket RPC server at the specified network address using the defatul 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 toy_rpc::client::Client; #[async_std::main] async fn main() { let addr = "ws://127.0.0.1:8080"; let client = Client::dial_http(addr).await.unwrap(); }
pub async fn dial_http(addr: &str) -> Result<Client<Connected>, Error>
[src]
Connects to an HTTP RPC server at the specified network address using WebSocket and the defatul codec.
It is recommended to use “ws://” as the url scheme as opposed to “http://”; however, internally the url scheme
is changed to “ws://”. Internally, DEFAULT_RPC_PATH="_rpc"
is appended to the end of addr
,
and the rest is the same is calling dial_websocket
.
If a network path were to be supplpied, the network path must end with a slash “/”.
For example, a valid path could be “ws://127.0.0.1/rpc/”.
Warning: WebSocket is used as the underlying transport protocol starting from version “0.5.0-beta.0”, and this will make client of versions later than “0.5.0-beta.0” incompatible with servers of versions earlier than “0.5.0-beta.0”.
This is enabled if and only if only 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 = "ws://127.0.0.1:8080/rpc/"; let client = Client::dial_http(addr).await.unwrap(); }
pub fn with_stream<T>(stream: T) -> Client<Connected> where
T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
[src]
T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
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; use toy_rpc::Client; #[async_std::main] async fn main() { let stream = TcpStream::connect("127.0.0.1:8080").await.unwrap(); let client = Client::with_stream(stream); }
impl Client<NotConnected>
[src]
pub fn with_codec<C>(codec: C) -> Client<Connected> where
C: ClientCodec + Send + Sync + 'static,
[src]
C: ClientCodec + Send + Sync + 'static,
Creates an RPC ’Clientwith a specified codec. The codec must implement
ClientCodectrait and
GracefulShutdown` trait.
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:8080"; let stream = TcpStream::connect(addr).await.unwrap(); let codec = Codec::new(stream); let client = Client::with_codec(codec); }
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("EchoService.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("EchoService.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("EchoService.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>
impl<Mode> Send for Client<Mode> where
Mode: Send,
Mode: Send,
impl<Mode> Sync for Client<Mode> where
Mode: Sync,
Mode: Sync,
impl<Mode> Unpin for Client<Mode> where
Mode: Unpin,
Mode: Unpin,
impl<Mode> !UnwindSafe for Client<Mode>
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>,