Struct Client

Source
pub struct Client<R: Read + Send + 'static, W: Write + Send> { /* private fields */ }
Expand description

Client represents a connection to some server that accepts MessagePack RPC requests.

Implementations§

Source§

impl<R, W> Client<R, W>
where R: Read + Send + 'static, W: Write + Send,

Source

pub fn new_for_stream<S>(stream: S) -> Client<S, S>
where S: Read + Write + Clone + Send + 'static,

Construct a new Client instance from a stream.

In order for this to work properly, the stream’s .clone() method must return a new handle to the shared underlying stream; in other words, it must be a shallow clone and not deep. TcpStream and UnixStream are known to do this, but other types should be aware of this restriction.

Source

pub fn new(reader: R, writer: W) -> Client<R, W>

Construct a new Client instance.

This will spawn a main loop thread which will take ownership of the Read instance, and which will exit when it detects EOF, or when it receives a 0 in lieu of a MessagePack data type identifier.

Source

pub fn call( &mut self, method: String, params: Vec<Value>, ) -> Result<Receiver<RpcResult>, WriteError>

Call a method via RPC and receive the response as a Receiver.

If an Err value is returned, it indicates some IO error that occurred while trying to make the call. An Ok value means that the call was successfully made. Calling .get() on its contents will block the thread until a response is received.

Source

pub fn call_cb<F: FnOnce(RpcResult) + Send + 'static>( &mut self, method: String, params: Vec<Value>, f: F, ) -> Result<(), WriteError>

Call a method via RPC and receive the response in a closure.

If an Err value is returned, it indicates some IO error that occurred while trying to make the call, and as a result the provided closure will never be invoked. If an Ok value is returned, then a new thread will be kicked off to listen for the response and pass it to the closure when it’s received.

§Panics

The new thread could conceivably panic if the Client instance gets cleaned up before the callback is invoked.

Source

pub fn call_sync( &mut self, method: String, params: Vec<Value>, ) -> Result<RpcResult, WriteError>

Call a method via RPC and synchronously wait for the response.

If an Err value is returned, it indicates some IO error that occurred while trying to make the call. An Ok value will contain the server’s response.

Trait Implementations§

Source§

impl<R, W> Drop for Client<R, W>
where R: Read + Send + 'static, W: Write + Send,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<R, W> Freeze for Client<R, W>
where W: Freeze,

§

impl<R, W> !RefUnwindSafe for Client<R, W>

§

impl<R, W> Send for Client<R, W>

§

impl<R, W> Sync for Client<R, W>
where W: Sync, R: Sync,

§

impl<R, W> Unpin for Client<R, W>
where W: Unpin, R: Unpin,

§

impl<R, W> !UnwindSafe for Client<R, W>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.