Skip to main content

MsgQueue

Struct MsgQueue 

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

Ordered queue of owned messages.

Implementations§

Source§

impl MsgQueue

Source

pub fn new() -> Self

Build an empty queue.

§Examples
use dynomite::msg::MsgQueue;
let q = MsgQueue::new();
assert!(q.is_empty());
Source

pub fn with_capacity(n: usize) -> Self

Build an empty queue with capacity for at least n messages.

§Examples
use dynomite::msg::MsgQueue;
let q = MsgQueue::with_capacity(8);
assert!(q.is_empty());
Source

pub fn push_back(&mut self, msg: Msg)

Append msg to the tail of the queue.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(7, MsgType::ReqRedisGet, true));
assert_eq!(q.len(), 1);
Source

pub fn push_front(&mut self, msg: Msg)

Push msg to the head of the queue.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_front(Msg::new(1, MsgType::ReqMcGet, true));
assert_eq!(q.len(), 1);
Source

pub fn pop_front(&mut self) -> Option<Msg>

Remove and return the head of the queue.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(1, MsgType::ReqMcGet, true));
assert!(q.pop_front().is_some());
assert!(q.pop_front().is_none());
Source

pub fn pop_back(&mut self) -> Option<Msg>

Remove and return the tail of the queue.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(1, MsgType::ReqMcGet, true));
q.push_back(Msg::new(2, MsgType::ReqMcGet, true));
assert_eq!(q.pop_back().unwrap().id(), 2);
Source

pub fn len(&self) -> usize

Number of messages currently in the queue.

§Examples
use dynomite::msg::MsgQueue;
assert_eq!(MsgQueue::new().len(), 0);
Source

pub fn is_empty(&self) -> bool

True when the queue is empty.

§Examples
use dynomite::msg::MsgQueue;
assert!(MsgQueue::new().is_empty());
Source

pub fn front(&self) -> Option<&Msg>

Borrow the front message without removing it.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(42, MsgType::ReqRedisGet, true));
assert_eq!(q.front().unwrap().id(), 42);
Source

pub fn front_mut(&mut self) -> Option<&mut Msg>

Mutably borrow the front message.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(1, MsgType::ReqRedisGet, true));
q.front_mut().unwrap().set_swallow(true);
Source

pub fn iter(&self) -> Iter<'_, Msg>

Iterate over the queue in front-to-back order.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(1, MsgType::ReqRedisGet, true));
q.push_back(Msg::new(2, MsgType::ReqRedisSet, true));
let ids: Vec<u64> = q.iter().map(|m| m.id()).collect();
assert_eq!(ids, vec![1, 2]);
Source

pub fn msg_get_id_lookup(&self, id: MsgId) -> Option<&Msg>

Find a message by id and return a shared reference.

This is the queue-side counterpart to the C dict_msg_id-shaped lookup that traverses the outstanding-msg list. Use crate::msg::index::MsgIndex when an O(1) lookup is required across many queues.

§Examples
use dynomite::msg::{Msg, MsgQueue, MsgType};

let mut q = MsgQueue::new();
q.push_back(Msg::new(99, MsgType::ReqRedisGet, true));
assert!(q.msg_get_id_lookup(99).is_some());
assert!(q.msg_get_id_lookup(1).is_none());

Trait Implementations§

Source§

impl Debug for MsgQueue

Source§

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

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

impl Default for MsgQueue

Source§

fn default() -> MsgQueue

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

impl<'a> IntoIterator for &'a MsgQueue

Source§

type Item = &'a Msg

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Msg>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,