Trait Handler

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

Source

fn do_handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>

Actual handling

Source

fn client_id(&self) -> u64

Unused

Source

fn for_new_client( &self, client_id: u64, peer_id: PubKey, dbid: u64, ) -> ChannelHandler

Create a channel handler

Source

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§

Source

fn handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>

Handle a message

Source

fn commit(&self)

Commit the persister transaction if any

Source

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.

Implementors§