Skip to main content

Context

Struct Context 

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

Owns and manages the set of active subscriptions.

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Creates an empty context with no subscriptions.

Source

pub fn subscription_count(&self) -> usize

Returns the number of active subscriptions currently stored in the context.

Source

pub fn contains_subscription(&self, id: SubscriptionId) -> bool

Returns true if a subscription with the given ID exists.

Source

pub fn get_subscription(&self, id: SubscriptionId) -> Option<&Subscription>

Returns a read-only reference to the subscription with the given ID, if it exists.

Source

pub fn get_subscription_mut( &mut self, id: SubscriptionId, ) -> Option<&mut Subscription>

Returns a mutable reference to the subscription with the given ID, if it exists.

Source

pub fn add_subscription( &mut self, config: SubscriptionConfig, ) -> Result<SubscriptionId, McrxError>

Adds a new subscription to the context.

The configuration is validated before insertion. If an identical subscription already exists, an error is returned instead of creating a duplicate.

This function creates and binds the underlying socket, but does not join the multicast group yet. Call join_subscription() to activate multicast reception.

Source

pub fn add_subscription_with_socket( &mut self, config: SubscriptionConfig, socket: Socket, ) -> Result<SubscriptionId, McrxError>

Adds a new subscription using a caller-provided socket.

The socket must already be bound to the destination port from config. This method preserves the existing lifecycle model: the context will still perform multicast join/leave operations later via join_subscription() and leave_subscription().

The supplied socket is switched to non-blocking mode so the receive APIs keep their usual non-blocking behavior.

Source

pub fn remove_subscription(&mut self, id: SubscriptionId) -> bool

Removes the subscription with the given ID.

Returns true if a subscription was removed and false if no matching subscription was found.

This uses swap_remove, so subscription order is not preserved.

Source

pub fn take_subscription(&mut self, id: SubscriptionId) -> Option<Subscription>

Removes the subscription with the given ID and returns it to the caller.

This preserves the current socket ownership and lifecycle state, which is useful when moving a subscription into an external event loop or runtime.

This uses swap_remove, so subscription order is not preserved.

Source

pub fn join_subscription(&mut self, id: SubscriptionId) -> Result<(), McrxError>

Joins the multicast group for the given subscription.

Source

pub fn leave_subscription( &mut self, id: SubscriptionId, ) -> Result<(), McrxError>

Leaves the multicast group for the given subscription while keeping the socket bound.

Source

pub fn subscriptions(&self) -> &[Subscription]

Returns a read-only slice of all subscriptions currently stored in the context.

Source

pub fn subscriptions_mut(&mut self) -> &mut [Subscription]

Returns a mutable slice of all subscriptions currently stored in the context.

Source

pub fn try_recv_any(&mut self) -> Result<Option<Packet>, McrxError>

Attempts to receive a single packet from any joined subscription without blocking.

Subscriptions are scanned using round-robin style fairness so that repeated calls do not always favor the first subscription.

Returns the first available packet, if any joined subscription currently has one ready to be read.

Source

pub fn try_recv_any_with_metadata( &mut self, ) -> Result<Option<PacketWithMetadata>, McrxError>

Attempts to receive a single packet with richer receive metadata from any joined subscription without blocking.

This uses the same round-robin fairness logic as try_recv_any().

Source

pub fn try_recv_batch_into( &mut self, out: &mut Vec<Packet>, max_packets: usize, ) -> Result<usize, McrxError>

Attempts to receive up to max_packets packets from any subscriptions without blocking.

This method repeatedly calls try_recv_any() using the same round-robin fairness logic and pushes received packets into the provided out vector.

Returns the number of packets that were added to out.

Behavior:

  • Stops early if no more packets are available
  • Does not block or wait for new packets
  • Preserves fairness across subscriptions
Source

pub fn try_recv_batch_with_metadata_into( &mut self, out: &mut Vec<PacketWithMetadata>, max_packets: usize, ) -> Result<usize, McrxError>

Attempts to receive up to max_packets packets with richer receive metadata from any subscriptions without blocking.

Source

pub fn try_recv_all_into( &mut self, out: &mut Vec<Packet>, ) -> Result<usize, McrxError>

Attempts to receive all currently available packets without blocking.

This is a convenience wrapper around try_recv_batch_into that continues draining until no more packets are available.

Note: this only drains packets that are currently available without blocking. It may result in unbounded growth of out if a large number of packets are queued, so callers should ensure capacity if needed.

Source

pub fn try_recv_all_with_metadata_into( &mut self, out: &mut Vec<PacketWithMetadata>, ) -> Result<usize, McrxError>

Attempts to receive all currently available packets with richer receive metadata without blocking.

Trait Implementations§

Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Context

Source§

fn default() -> Context

Returns the “default value” for a type. Read more

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.