[−][src]Struct rpc_toy::Server
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]
F: Fn(&[Value]) -> Option<Value> + 'static + Send,
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 usefunction
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
Auto Trait Implementations
impl RefUnwindSafe for Server
[src]
impl Send for Server
[src]
impl Sync for Server
[src]
impl Unpin for Server
[src]
impl UnwindSafe for Server
[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>,