[][src]Struct splinter::network::dispatch::Dispatcher

pub struct Dispatcher<MT: Any + Hash + Eq + Debug + Clone> { /* fields omitted */ }

Dispatches messages to handlers.

The dispatcher routes messages of a specific message type to one of a set of handlers that have been supplied via the set_handler function. It owns a Sender for sending messages on a network, which is provided to the handlers. The handlers may use the sender for replying to or broadcasting messages, as needed.

These messages are run in the same thread as the dispatch function is called. Any asynchronous activity done by a handler must be managed by the handler. These asynchronous operations must return success for the handler immediately, as the expectation is that the dispatcher should not block the current thread.

Message Types (MT) merely need to implement Hash, Eq and Debug (for unknown message type results). Beyond that, there are no other requirements.

Methods

impl<MT: Any + Hash + Eq + Debug + Clone> Dispatcher<MT>[src]

pub fn new(network_sender: Box<dyn Sender<SendRequest>>) -> Self[src]

Creates a Dispatcher

Creates a dispatcher with a given Sender to supply to handlers when they are executed.

pub fn set_handler<T>(
    &mut self,
    message_type: MT,
    handler: Box<dyn Handler<MT, T>>
) where
    T: FromMessageBytes
[src]

Set a handler for a given Message Type.

This sets a handler for a given message type. Only one handler may exist per message type. If a user wishes to run a series handlers, they must supply a single handler that composes the series.

pub fn dispatch(
    &self,
    source_peer_id: &str,
    message_type: &MT,
    message_bytes: Vec<u8>
) -> Result<(), DispatchError>
[src]

Dispatch a message by type.

This dispatches a message (in raw byte form) as a given message type. The message will be handled by a handler that has been set previously via set_handler, if one exists.

Errors

A DispatchError is returned if either there is no handler for the given message type, or an error occurs while handling the messages (e.g. the message cannot be deserialized).

Auto Trait Implementations

impl<MT> !RefUnwindSafe for Dispatcher<MT>

impl<MT> Send for Dispatcher<MT> where
    MT: Send

impl<MT> !Sync for Dispatcher<MT>

impl<MT> Unpin for Dispatcher<MT> where
    MT: Unpin

impl<MT> !UnwindSafe for Dispatcher<MT>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoSql for T

impl<T> SafeBorrow<T> for T where
    T: ?Sized

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,