Struct mpack::rpc::Client
[−]
[src]
pub struct Client<R: Read + Send + 'static, W: Write + Send> { /* fields omitted */ }
Client
represents a connection to some server that accepts
MessagePack RPC requests.
Methods
impl<R, W> Client<R, W> where
R: Read + Send + 'static,
W: Write + Send,
[src]
R: Read + Send + 'static,
W: Write + Send,
fn new_for_stream<S>(stream: S) -> Client<S, S> where
S: Read + Write + Clone + Send + 'static,
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.
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.
fn call(
&mut self,
method: String,
params: Vec<Value>
) -> Result<Receiver<RpcResult>, WriteError>
&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.
fn call_cb<F: FnOnce(RpcResult) -> () + Send + 'static>(
&mut self,
method: String,
params: Vec<Value>,
f: F
) -> Result<(), WriteError>
&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.
fn call_sync(
&mut self,
method: String,
params: Vec<Value>
) -> Result<RpcResult, WriteError>
&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
impl<R, W> Drop for Client<R, W> where
R: Read + Send + 'static,
W: Write + Send,
[src]
R: Read + Send + 'static,
W: Write + Send,