[−][src]Struct rpc_toy::Client
An RPC client This is the main struct that should be used for implementing an RPC client.
Implementations
impl Client
[src]
pub fn new(addr: &str) -> Result<Self, Error>
[src]
Creates a new client that connects to an RPC server
Arguments:
addr
The address the TCP client should connect to this should be in the form "host:port"
Example:
use rpc_toy::Client; let client = Client::new("127.0.0.1:3001");
pub fn call(
&mut self,
fn_name: &str,
args: &[Value]
) -> Result<Option<Value>, Error>
[src]
&mut self,
fn_name: &str,
args: &[Value]
) -> Result<Option<Value>, Error>
Invokes an RPC, this is the mechanism to "call" functions on a remote server
Arguments:
fn_name
: The name of the function to call NOTE: The server MUST have registered this function, otherwise (currently) expect weird stuff to happen :)args
a slice ofserde_json::Value
s. This represents the arguments that will be passed onto the server's functions
Returns:
- a
Result<Option<serde_json::Value>>>
, which isOk
if nothing errored out theOption
will beNone
if this is a void function, otherwise it will beSome(value)
wherevalue
is aserde_json::Value
representing the return value of the function
Example:
use rpc_toy::Client; let mut client = Client::new("127.0.0.1:3001").unwrap(); let one = serde_json::to_value(1u32).unwrap(); let two = serde_json::to_value(2u32).unwrap(); let args = vec![one, two]; let res = client.call("Add", &args).unwrap(); let three: u32 = serde_json::from_value(res.unwrap()).unwrap(); assert_eq!(three, 3);
Auto Trait Implementations
impl RefUnwindSafe for Client
[src]
impl Send for Client
[src]
impl Sync for Client
[src]
impl Unpin for Client
[src]
impl UnwindSafe for Client
[src]
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, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
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>,