[][src]Struct rpc_toy::Client

pub struct Client { /* fields omitted */ }

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]

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 of serde_json::Values. This represents the arguments that will be passed onto the server's functions

Returns:

  • a Result<Option<serde_json::Value>>>, which is Ok if nothing errored out the Option will be None if this is a void function, otherwise it will be Some(value) where value is a serde_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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.