Skip to main content

Subscription

Struct Subscription 

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

Represents a registered subscription stored inside a context.

Implementations§

Source§

impl Subscription

Source

pub fn new( id: SubscriptionId, config: SubscriptionConfig, socket: Socket, ) -> Self

Creates a new subscription from an ID, configuration, and socket.

This is a low-level constructor. Callers are responsible for providing a socket that is compatible with the subscription configuration. For the checked convenience path, prefer Context::add_subscription_with_socket().

Source

pub fn id(&self) -> SubscriptionId

Returns the subscription’s ID.

Source

pub fn config(&self) -> &SubscriptionConfig

Returns a read-only reference to the subscription’s configuration.

Source

pub fn socket(&self) -> &Socket

Returns a read-only reference to the subscription’s socket.

Source

pub fn socket_mut(&mut self) -> &mut Socket

Returns a mutable reference to the subscription’s socket.

This is useful when an external event loop or registry needs mutable socket access during registration.

Source

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

Attempts to receive a single packet without blocking.

Returns:

  • Ok(Some(packet)) if a packet was received,
  • Ok(None) if no packet is currently available,
  • Err(...) on an actual receive failure.
Source

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

Attempts to receive a single packet together with richer receive metadata without blocking.

Source

pub fn as_raw_fd(&self) -> RawFd

Returns the raw Unix file descriptor of the underlying socket.

This is useful for integrating subscriptions into external event loops.

Source

pub fn local_addr(&self) -> Result<SocketAddr, McrxError>

Returns the local socket address currently bound by this subscription.

Source

pub fn into_socket(self) -> Socket

Consumes the subscription and returns its owned socket.

This is useful when handing a joined or bound socket off to an external event loop or async runtime.

Source

pub fn into_parts(self) -> SubscriptionParts

Consumes the subscription and returns all owned parts.

Source

pub fn state(&self) -> SubscriptionState

Returns the current lifecycle state of the subscription.

This can be used by callers to inspect whether the subscription is currently joined to its multicast group or only bound.

Source

pub fn is_joined(&self) -> bool

Returns true if the subscription is currently joined to its multicast group.

This is a convenience helper for checking whether the subscription is in the SubscriptionState::Joined state.

Source

pub fn mark_joined(&mut self) -> Result<(), McrxError>

Marks the subscription as joined.

This should be called after a successful multicast join operation on the underlying socket.

Returns an error if the subscription is already in the joined state.

Source

pub fn mark_bound(&mut self) -> Result<(), McrxError>

Marks the subscription as bound (not joined).

This should be called after leaving a multicast group, while keeping the underlying socket open and bound.

Returns an error if the subscription is already in the bound state.

Trait Implementations§

Source§

impl AsFd for Subscription

Available on Unix only.
Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for Subscription

Available on Unix only.
Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for Subscription

Source§

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

Formats the value using the given formatter. 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.