Skip to main content

ByteMerge

Struct ByteMerge 

Source
pub struct ByteMerge { /* private fields */ }
Expand description

The one bounded multi-input primitive in the byte layer: N byte sources reduced to one output stream. See the module docs.

Implementations§

Source§

impl ByteMerge

Source

pub fn new(policy: MergePolicy, num_sources: usize, max_queued: usize) -> Self

Construct a merge for num_sources sources (0..num_sources), applying policy, with its output queue bounded to max_queued messages.

Panics if num_sources == 0, max_queued == 0, or (for MergePolicy::Failover) primary/secondary are not both within 0..num_sources — all three are construction-time configuration mistakes, not remote input, so they panic rather than returning a Result a caller could ignore.

Source

pub fn num_sources(&self) -> usize

How many sources this merge accepts feed calls from.

Source

pub fn len(&self) -> usize

Messages currently queued, awaiting ByteMerge::poll. Never exceeds the max_queued bound this merge was constructed with.

Source

pub fn is_empty(&self) -> bool

true if no messages are currently queued.

Source

pub fn feed( &mut self, source: SourceId, msg: Bytes, at: Timestamp, ) -> Result<(), MergeError>

Feed one discrete message from source, observed at at.

Whether it is forwarded to ByteMerge::poll depends on the policy: every message is forwarded under MergePolicy::FirstArrival; under MergePolicy::Failover only the currently-active source’s messages are (see that variant’s docs for exactly when that is, and the switch-back rule).

Returns MergeError::UnknownSource if source is out of range, or MergeError::QueueFull if the output queue is already at its bound — in both cases nothing from this call is buffered.

Source

pub fn poll(&mut self) -> Option<(Bytes, Timestamp)>

Pull the next merged message, in the order it was forwarded by ByteMerge::feed.

Source

pub fn next_deadline(&self) -> Option<Timestamp>

When ByteMerge::on_deadline should next be called to check a MergePolicy::Failover silence timeout.

None under MergePolicy::FirstArrival (arrival-driven, no clock needed) and under Failover before primary has produced its first message (see that variant’s docs).

Source

pub fn on_deadline(&mut self, now: Timestamp)

Drive time-based transitions: under MergePolicy::Failover, switch to secondary if primary has been silent for at least silence_timeout as of now. A no-op under MergePolicy::FirstArrival.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.