RpcClient

Struct RpcClient 

Source
pub struct RpcClient<T, C: Codec = BincodeCodec>
where T: MessageTransport<C>,
{ /* private fields */ }

Implementations§

Source§

impl<T: MessageTransport<BincodeCodec> + 'static> RpcClient<T, BincodeCodec>

Source

pub fn new(transport: T) -> Self

Examples found in repository?
examples/rpc_client_server.rs (line 88)
82async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
83    println!("[Client] Connecting to RPC server");
84
85    let transport = SharedMemoryTransport::connect_client(SERVICE_NAME)?;
86    let msg_transport = MessageTransportAdapter::new(transport);
87
88    let client = RpcClient::new(msg_transport);
89    let _handle = client.start();
90
91    println!("[Client] Connected!\n");
92
93    println!("[Client] Calling add(10, 32)");
94    let resp: AddResponse = client.call("add", &AddRequest { a: 10, b: 32 }).await?;
95    println!("[Client] Result: {}\n", resp.result);
96
97    println!("[Client] Calling add(100, 200)");
98    let resp: AddResponse = client.call("add", &AddRequest { a: 100, b: 200 }).await?;
99    println!("[Client] Result: {}\n", resp.result);
100
101    println!("[Client] Calling echo(\"Hello, RPC!\")");
102    let resp: EchoResponse = client
103        .call(
104            "echo",
105            &EchoRequest {
106                message: "Hello, RPC!".to_string(),
107            },
108        )
109        .await?;
110    println!(
111        "[Client] Result: message=\"{}\", length={}\n",
112        resp.message, resp.length
113    );
114
115    println!("[Client] Calling unknown method");
116    let result: Result<(), _> = client.call("unknown", &()).await;
117    match result {
118        Ok(_) => println!("[Client] Unexpected success"),
119        Err(e) => println!("[Client] Got expected error: {}\n", e),
120    }
121
122    client.close().await?;
123    println!("[Client] Done!");
124
125    Ok(())
126}
Source

pub fn with_timeout(transport: T, default_timeout: Duration) -> Self

Source§

impl<T, C> RpcClient<T, C>
where T: MessageTransport<C> + 'static, C: Codec + Clone + Default + 'static,

Source

pub fn with_codec(transport: T, codec: C) -> Self

Source

pub fn with_codec_and_timeout( transport: T, codec: C, default_timeout: Duration, ) -> Self

Source

pub fn start(&self) -> RpcClientHandle

Examples found in repository?
examples/rpc_client_server.rs (line 89)
82async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
83    println!("[Client] Connecting to RPC server");
84
85    let transport = SharedMemoryTransport::connect_client(SERVICE_NAME)?;
86    let msg_transport = MessageTransportAdapter::new(transport);
87
88    let client = RpcClient::new(msg_transport);
89    let _handle = client.start();
90
91    println!("[Client] Connected!\n");
92
93    println!("[Client] Calling add(10, 32)");
94    let resp: AddResponse = client.call("add", &AddRequest { a: 10, b: 32 }).await?;
95    println!("[Client] Result: {}\n", resp.result);
96
97    println!("[Client] Calling add(100, 200)");
98    let resp: AddResponse = client.call("add", &AddRequest { a: 100, b: 200 }).await?;
99    println!("[Client] Result: {}\n", resp.result);
100
101    println!("[Client] Calling echo(\"Hello, RPC!\")");
102    let resp: EchoResponse = client
103        .call(
104            "echo",
105            &EchoRequest {
106                message: "Hello, RPC!".to_string(),
107            },
108        )
109        .await?;
110    println!(
111        "[Client] Result: message=\"{}\", length={}\n",
112        resp.message, resp.length
113    );
114
115    println!("[Client] Calling unknown method");
116    let result: Result<(), _> = client.call("unknown", &()).await;
117    match result {
118        Ok(_) => println!("[Client] Unexpected success"),
119        Err(e) => println!("[Client] Got expected error: {}\n", e),
120    }
121
122    client.close().await?;
123    println!("[Client] Done!");
124
125    Ok(())
126}
Source

pub fn transport(&self) -> Arc<T>

Source

pub fn stream_manager(&self) -> Arc<StreamManager<C>>

Source

pub async fn call<Req, Resp>(&self, method: &str, request: &Req) -> Result<Resp>
where Req: Serialize, Resp: for<'de> Deserialize<'de>,

Examples found in repository?
examples/rpc_client_server.rs (line 94)
82async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
83    println!("[Client] Connecting to RPC server");
84
85    let transport = SharedMemoryTransport::connect_client(SERVICE_NAME)?;
86    let msg_transport = MessageTransportAdapter::new(transport);
87
88    let client = RpcClient::new(msg_transport);
89    let _handle = client.start();
90
91    println!("[Client] Connected!\n");
92
93    println!("[Client] Calling add(10, 32)");
94    let resp: AddResponse = client.call("add", &AddRequest { a: 10, b: 32 }).await?;
95    println!("[Client] Result: {}\n", resp.result);
96
97    println!("[Client] Calling add(100, 200)");
98    let resp: AddResponse = client.call("add", &AddRequest { a: 100, b: 200 }).await?;
99    println!("[Client] Result: {}\n", resp.result);
100
101    println!("[Client] Calling echo(\"Hello, RPC!\")");
102    let resp: EchoResponse = client
103        .call(
104            "echo",
105            &EchoRequest {
106                message: "Hello, RPC!".to_string(),
107            },
108        )
109        .await?;
110    println!(
111        "[Client] Result: message=\"{}\", length={}\n",
112        resp.message, resp.length
113    );
114
115    println!("[Client] Calling unknown method");
116    let result: Result<(), _> = client.call("unknown", &()).await;
117    match result {
118        Ok(_) => println!("[Client] Unexpected success"),
119        Err(e) => println!("[Client] Got expected error: {}\n", e),
120    }
121
122    client.close().await?;
123    println!("[Client] Done!");
124
125    Ok(())
126}
Source

pub async fn call_with_timeout<Req, Resp>( &self, method: &str, request: &Req, timeout: Duration, ) -> Result<Resp>
where Req: Serialize, Resp: for<'de> Deserialize<'de>,

Source

pub async fn call_server_stream<Req, Resp>( &self, method: &str, request: &Req, ) -> Result<StreamReceiver<Resp, C>>
where Req: Serialize, Resp: for<'de> Deserialize<'de>,

Source

pub async fn notify<Req: Serialize>( &self, method: &str, request: &Req, ) -> Result<()>

Source

pub async fn call_raw(&self, method: &str, payload: Vec<u8>) -> Result<Vec<u8>>

Source

pub async fn call_raw_with_timeout( &self, method: &str, payload: Vec<u8>, timeout: Duration, ) -> Result<Vec<u8>>

Source

pub fn is_connected(&self) -> bool

Source

pub fn active_streams(&self) -> usize

Source

pub async fn close(&self) -> Result<()>

Examples found in repository?
examples/rpc_client_server.rs (line 122)
82async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
83    println!("[Client] Connecting to RPC server");
84
85    let transport = SharedMemoryTransport::connect_client(SERVICE_NAME)?;
86    let msg_transport = MessageTransportAdapter::new(transport);
87
88    let client = RpcClient::new(msg_transport);
89    let _handle = client.start();
90
91    println!("[Client] Connected!\n");
92
93    println!("[Client] Calling add(10, 32)");
94    let resp: AddResponse = client.call("add", &AddRequest { a: 10, b: 32 }).await?;
95    println!("[Client] Result: {}\n", resp.result);
96
97    println!("[Client] Calling add(100, 200)");
98    let resp: AddResponse = client.call("add", &AddRequest { a: 100, b: 200 }).await?;
99    println!("[Client] Result: {}\n", resp.result);
100
101    println!("[Client] Calling echo(\"Hello, RPC!\")");
102    let resp: EchoResponse = client
103        .call(
104            "echo",
105            &EchoRequest {
106                message: "Hello, RPC!".to_string(),
107            },
108        )
109        .await?;
110    println!(
111        "[Client] Result: message=\"{}\", length={}\n",
112        resp.message, resp.length
113    );
114
115    println!("[Client] Calling unknown method");
116    let result: Result<(), _> = client.call("unknown", &()).await;
117    match result {
118        Ok(_) => println!("[Client] Unexpected success"),
119        Err(e) => println!("[Client] Got expected error: {}\n", e),
120    }
121
122    client.close().await?;
123    println!("[Client] Done!");
124
125    Ok(())
126}

Trait Implementations§

Source§

impl<T, C> Debug for RpcClient<T, C>
where T: MessageTransport<C>, C: Codec + Clone,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, C> Freeze for RpcClient<T, C>
where C: Freeze,

§

impl<T, C = BincodeCodec> !RefUnwindSafe for RpcClient<T, C>

§

impl<T, C> Send for RpcClient<T, C>

§

impl<T, C> Sync for RpcClient<T, C>

§

impl<T, C> Unpin for RpcClient<T, C>
where C: Unpin,

§

impl<T, C = BincodeCodec> !UnwindSafe for RpcClient<T, C>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V