mesh_node::local_node

Trait HandlePortEvent

Source
pub trait HandlePortEvent: 'static + Send {
    // Required methods
    fn message<'a>(
        &mut self,
        control: &mut PortControl<'_, 'a>,
        message: Message<'a>,
    ) -> Result<(), HandleMessageError>;
    fn close(&mut self, control: &mut PortControl<'_, '_>);
    fn fail(&mut self, control: &mut PortControl<'_, '_>, err: NodeError);
    fn drain(&mut self) -> Vec<OwnedMessage>;
}
Expand description

Trait implemented by port event handlers.

Such an implementation can be associated with a port by calling Port::set_handler.

Required Methods§

Source

fn message<'a>( &mut self, control: &mut PortControl<'_, 'a>, message: Message<'a>, ) -> Result<(), HandleMessageError>

Handles a new message for the port.

If an error is returned, the port will be failed (and the caller will call the fail method).

Source

fn close(&mut self, control: &mut PortControl<'_, '_>)

Handles the port closing.

Source

fn fail(&mut self, control: &mut PortControl<'_, '_>, err: NodeError)

Handles a port failure.

Source

fn drain(&mut self) -> Vec<OwnedMessage>

Returns all unconsumed messages.

This is used when the handler is being released, such as when sending the port to another node.

Implementors§