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
RefCellfor 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: MessageCodectype 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>
impl<T, C: MessageCodec> NetNotifiedQueue<T, C>
Sourcepub fn new(endpoint: Endpoint, codec: C) -> Self
pub fn new(endpoint: Endpoint, codec: C) -> Self
Create a new queue with the given endpoint and codec.
Sourcepub fn with_address(address: NetworkAddress, codec: C) -> Self
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.
Sourcepub fn endpoint(&self) -> &Endpoint
pub fn endpoint(&self) -> &Endpoint
Get the endpoint for this queue.
Senders use this endpoint to address messages to this queue.
Sourcepub fn try_recv(&self) -> Option<T>
pub fn try_recv(&self) -> Option<T>
Try to receive a message without blocking.
Returns None if no message is available.
Sourcepub fn messages_received(&self) -> u64
pub fn messages_received(&self) -> u64
Get the total number of messages received.
Sourcepub fn messages_dropped(&self) -> u64
pub fn messages_dropped(&self) -> u64
Get the number of messages dropped due to deserialization errors.
Source§impl<T: DeserializeOwned, C: MessageCodec> NetNotifiedQueue<T, C>
impl<T: DeserializeOwned, C: MessageCodec> NetNotifiedQueue<T, C>
Sourcepub fn recv(&self) -> RecvFuture<'_, T, C> ⓘ
pub fn recv(&self) -> RecvFuture<'_, T, C> ⓘ
Async receive - waits for a message.
Returns None if the queue is closed and empty.