pub trait Handler {
// Required methods
fn do_handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>;
fn client_id(&self) -> u64;
fn for_new_client(
&self,
client_id: u64,
peer_id: PubKey,
dbid: u64,
) -> ChannelHandler;
fn node(&self) -> &Arc<Node>;
// Provided methods
fn handle(&self, msg: Message) -> Result<Box<dyn SerBolt>> { ... }
fn commit(&self) { ... }
fn with_persist(
&self,
f: impl FnOnce(&Node) -> Result<()>,
) -> Result<Mutations> { ... }
}
Expand description
A protocol handler The handle function takes an incoming message, handles it and returns a response.
There are two implementations of this trait - RootHandler
for node level
messages and ChannelHandler
for channel level messages.
Required Methods§
Sourcefn for_new_client(
&self,
client_id: u64,
peer_id: PubKey,
dbid: u64,
) -> ChannelHandler
fn for_new_client( &self, client_id: u64, peer_id: PubKey, dbid: u64, ) -> ChannelHandler
Create a channel handler
Sourcefn node(&self) -> &Arc<Node>
fn node(&self) -> &Arc<Node>
Get the associated signing node.
Note that if you want to perform an operation that can result in a mutation
of the node state requiring a persist, and your persister writes to the cloud,
you must use Handler::with_persist
instead.
Provided Methods§
Sourcefn with_persist(&self, f: impl FnOnce(&Node) -> Result<()>) -> Result<Mutations>
fn with_persist(&self, f: impl FnOnce(&Node) -> Result<()>) -> Result<Mutations>
Perform an operation on the Node that requires persistence.
The operation must not mutate if it fails (returns an error).
You must call Handler::commit
after you persist the mutations in the
cloud.
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.