Skip to main content

NetNotifiedQueue

Struct NetNotifiedQueue 

Source
pub struct NetNotifiedQueue<T, C: MessageCodec> { /* private fields */ }
Expand description

Type-safe message queue with async notification.

Receives raw bytes, deserializes them to type T, and queues them. Consumers can async wait for messages using recv() or poll with try_recv().

§Design

  • Uses RefCell for single-threaded runtime (no Mutex overhead)
  • Waker-based notification wakes all waiting consumers
  • Deserializes on receive (producer side) to fail fast on bad messages
  • Pluggable codec via C: MessageCodec type parameter

§Type Safety

The type T is baked in at compile time. Only messages that deserialize to T will be accepted. Invalid messages log an error and are dropped.

Implementations§

Source§

impl<T, C: MessageCodec> NetNotifiedQueue<T, C>

Source

pub fn new(endpoint: Endpoint, codec: C) -> Self

Create a new queue with the given endpoint and codec.

Source

pub fn with_address(address: NetworkAddress, codec: C) -> Self

Create a new queue with a dynamically allocated endpoint.

Uses the provided address with a new random UID.

Source

pub fn endpoint(&self) -> &Endpoint

Get the endpoint for this queue.

Senders use this endpoint to address messages to this queue.

Source

pub fn try_recv(&self) -> Option<T>

Try to receive a message without blocking.

Returns None if no message is available.

Source

pub fn is_empty(&self) -> bool

Check if the queue is empty.

Source

pub fn len(&self) -> usize

Get the number of messages currently in the queue.

Source

pub fn messages_received(&self) -> u64

Get the total number of messages received.

Source

pub fn messages_dropped(&self) -> u64

Get the number of messages dropped due to deserialization errors.

Source

pub fn close(&self)

Mark the queue as closed.

After closing, recv() will return None when the queue is empty instead of waiting for more messages.

Source

pub fn is_closed(&self) -> bool

Check if the queue is closed.

Source§

impl<T: DeserializeOwned, C: MessageCodec> NetNotifiedQueue<T, C>

Source

pub fn recv(&self) -> RecvFuture<'_, T, C>

Async receive - waits for a message.

Returns None if the queue is closed and empty.

Trait Implementations§

Source§

impl<T: DeserializeOwned + 'static, C: MessageCodec> MessageReceiver for NetNotifiedQueue<T, C>

Source§

fn receive(&self, payload: &[u8])

Process an incoming message payload. Read more
Source§

fn is_stream(&self) -> bool

Whether this receiver handles a stream of messages (default: true). Read more

Auto Trait Implementations§

§

impl<T, C> !Freeze for NetNotifiedQueue<T, C>

§

impl<T, C> !RefUnwindSafe for NetNotifiedQueue<T, C>

§

impl<T, C> Send for NetNotifiedQueue<T, C>
where C: Send, T: Send,

§

impl<T, C> !Sync for NetNotifiedQueue<T, C>

§

impl<T, C> Unpin for NetNotifiedQueue<T, C>
where C: Unpin, T: Unpin,

§

impl<T, C> UnwindSafe for NetNotifiedQueue<T, C>
where C: UnwindSafe, T: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more