pub struct Server {
pub handles: SyncHashMap<String, Box<dyn Stub>>,
pub codec: Codecs,
pub stub: ServerStub,
}Fields§
§handles: SyncHashMap<String, Box<dyn Stub>>§codec: Codecs§stub: ServerStubImplementations§
Source§impl Server
impl Server
Sourcepub fn register<H>(&mut self, name: &str, handle: H)where
H: Stub + 'static,
pub fn register<H>(&mut self, name: &str, handle: H)where
H: Stub + 'static,
register a handle to server
use mco_rpc::server::{Handler};
pub struct H{}
impl Handler for H{
type Req = i32;
type Resp = i32;
fn handle(&self, req: Self::Req) -> mco::std::errors::Result<Self::Resp> {
return Ok(req);
}
}
Sourcepub fn register_fn<Req: DeserializeOwned + 'static, Resp: Serialize + 'static, F>(
&mut self,
name: &str,
f: F,
)
pub fn register_fn<Req: DeserializeOwned + 'static, Resp: Serialize + 'static, F>( &mut self, name: &str, f: F, )
register a func into server for example:
use mco_rpc::server::{Server};
let mut s = Server::default();
fn handle(req: i32) -> mco::std::errors::Result<i32> {
return Ok(req + 1);
}
//s.codec = Codecs::JsonCodec(JsonCodec{});
s.register_fn("handle", handle);
s.register_fn("handle_fn2", |arg:i32| -> mco::std::errors::Result<i32>{
Ok(1)
});pub fn serve<A>(self, addr: A)where
A: ToSocketAddrs,
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl !UnwindSafe for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more