[][src]Struct rpc_toy::Server

pub struct Server { /* fields omitted */ }

A struct representing an RPC server, this is to be used to implement the server.

Implementations

impl Server[src]

pub fn new() -> Self[src]

Creates a new RPC server

pub fn register<F>(&mut self, fn_name: &str, function: F) where
    F: Fn(&[Value]) -> Option<Value> + 'static + Send
[src]

Registers functions to be used in the RPC server only functions registered using this function can be called from the client

Arguments:

  • fn_name the name of the function to register, this MUST be the same name the client expects to use
  • function the function to run once the RPC is invoked

Example:

use rpc_toy::Server;
let mut server = Server::new();
server.register("Add", |args| {
    let one = args.get(0).unwrap();
    let two = args.get(1).unwrap();
    let one = serde_json::from_value::<u32>(one.clone()).unwrap();
    let two = serde_json::from_value::<u32>(two.clone()).unwrap();
    let three = one + two;
    return Some(serde_json::to_value(three).unwrap());
});

pub fn listen(&self, addr: &str) -> Result<(), Error>[src]

Listen to RPC connections This function must be run in order to start listening for calls over the network

Arguments:

  • addr: An address to bind to, must be in the form: "host:port"

Examples:

use rpc_toy::Server;
let mut server = Server::new();
server.listen("127.0.0.1:3001").unwrap();

Trait Implementations

impl Default for Server[src]

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.