Skip to main content

RoutingStrategy

Trait RoutingStrategy 

Source
pub trait RoutingStrategy<Route: DeliveryRoute + Clone + PartialEq>: Clone {
    type Observation;
    type Error;

    // Required methods
    fn select(
        &mut self,
        members: &[Route],
        message: &<Route::Protocol as Protocol>::Msg,
    ) -> Option<usize>;
    fn observe(
        &mut self,
        _members: &[Route],
        observation: Self::Observation,
    ) -> Result<(), RoutingObservationRejection<Self::Observation, Self::Error>>;

    // Provided methods
    fn added(&mut self, _recipient: Route) { ... }
    fn removed(&mut self, _index: usize, _recipient: Route, _remaining: usize) { ... }
}
Expand description

Static recipient-selection policy used by Router.

Implementations receive the current membership snapshot and return at most one index into it. Returning an out-of-range index is a typed RouterError::InvalidSelection; the command is returned and the cloned policy candidate is discarded without committing policy state. Policies perform no effects and obtain no ambient entropy.

Required Associated Types§

Source

type Observation

Closed observation type accepted by this policy.

Source

type Error

Concrete observation rejection reason.

Required Methods§

Source

fn select( &mut self, members: &[Route], message: &<Route::Protocol as Protocol>::Msg, ) -> Option<usize>

Select at most one index from this exact typed membership snapshot.

Returning None means no member is currently eligible. The selected route receives ownership of the message, so unicast routing does not require the destination protocol’s message to implement Clone.

Source

fn observe( &mut self, _members: &[Route], observation: Self::Observation, ) -> Result<(), RoutingObservationRejection<Self::Observation, Self::Error>>

Fold one typed observation against the same membership snapshot.

§Errors

Returns the exact owned observation and concrete reason when evidence is unknown, stale, or contradictory. Router discards the policy candidate on rejection, so no partial policy mutation is committed.

Provided Methods§

Source

fn added(&mut self, _recipient: Route)

Update policy-local state after one new membership is committed.

Source

fn removed(&mut self, _index: usize, _recipient: Route, _remaining: usize)

Repair policy-local position after a membership removal.

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§