Skip to main content

ServiceStatic

Trait ServiceStatic 

Source
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:

Required Associated Constants§

Source

const SERVICE_NAME: &'static str

For server_mux_struct to match

Required Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl<S: ServiceStatic<C>, C: Codec> ServiceStatic<C> for Arc<S>

Source§

const SERVICE_NAME: &'static str = S::SERVICE_NAME

Source§

fn serve(&self, req: APIServerReq<C>) -> impl Future<Output = ()> + Send + Sized

Implementors§

Source§

impl<C: Codec> ServiceStatic<C> for ServiceMuxDyn<C>

Source§

const SERVICE_NAME: &'static str = ""