pub trait ServiceStatic<C: Codec>:
Send
+ Sync
+ 'static
+ Sized {
const SERVICE_NAME: &'static str;
// Required method
fn serve(
&self,
req: APIServerReq<C>,
) -> impl Future<Output = ()> + Send + Sized;
}Expand description
Service handling code generated by macro
A ServiceStatic can be acquired by:
Arc<T>whereT: ServiceStatic,- attr macro service: a class with multi method, if only one service, ignore APIServerReq::service.
- attr macro service_mux_struct: a struct that contains several service, match APIServerReq::service by ServiceStatic::SERVICE_NAME field,
- ServiceMuxDyn: match multiple
dyn ServiceDynwith SERVICE_NAME (ServiceStatic auto impl ServiceDyn)
Required Associated Constants§
Sourceconst SERVICE_NAME: &'static str
const SERVICE_NAME: &'static str
For server_mux_struct to match
Required Methods§
Sourcefn serve(&self, req: APIServerReq<C>) -> impl Future<Output = ()> + Send + Sized
fn serve(&self, req: APIServerReq<C>) -> impl Future<Output = ()> + Send + Sized
the #[service] macro should generate code like this:
match req.method
match req.decode::<RequestType>() {
Err(())=>{
req.set_rpc_error(razor_rpc_core::error::RpcIntErr::Decode);
returnl
}
Ok(arg)=>{
match self.#method(arg).await {
Ok(resp)=>{
req.set_result(resp);
}
Err(e)=>{
req.set_error::<E: RpcErrCodec>(e)
}
}
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.