pub trait RpcService: Sized {
// Required method
fn register_handlers(registry: &mut ServiceRegistry<Self>);
// Provided method
fn service_name() -> &'static str { ... }
}
Expand description
A standard RPC server that handles messages.
use datacake_rpc::{RpcService, ServiceRegistry};
pub struct MyService;
impl RpcService for MyService {
// This is an optional method which can be used
// to avoid naming conflicts between two services.
// By default this uses the type name of the service.
fn service_name() -> &'static str {
"my-lovely-service"
}
fn register_handlers(registry: &mut ServiceRegistry<Self>) {
// Register each one of our handlers here.
}
}
Required Methods§
Sourcefn register_handlers(registry: &mut ServiceRegistry<Self>)
fn register_handlers(registry: &mut ServiceRegistry<Self>)
Register all message handlers for this server with the registry.
See ServiceRegistry for more information.
Provided Methods§
Sourcefn service_name() -> &'static str
fn service_name() -> &'static str
An optional name of the service.
This can be used to prevent overlaps or clashes in handlers as two services may handle the same message but behave differently, to distinguish between these services, the message paths also use the service name to create a unique key.
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.