pub struct MsgQueue { /* private fields */ }Expand description
Ordered queue of owned messages.
Implementations§
Source§impl MsgQueue
impl MsgQueue
Sourcepub fn new() -> Self
pub fn new() -> Self
Build an empty queue.
§Examples
use dynomite::msg::MsgQueue;
let q = MsgQueue::new();
assert!(q.is_empty());Sourcepub fn with_capacity(n: usize) -> Self
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());Sourcepub fn push_back(&mut self, msg: Msg)
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);Sourcepub fn push_front(&mut self, msg: Msg)
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);Sourcepub fn pop_front(&mut self) -> Option<Msg>
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());Sourcepub fn pop_back(&mut self) -> Option<Msg>
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);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of messages currently in the queue.
§Examples
use dynomite::msg::MsgQueue;
assert_eq!(MsgQueue::new().len(), 0);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when the queue is empty.
§Examples
use dynomite::msg::MsgQueue;
assert!(MsgQueue::new().is_empty());Sourcepub fn front(&self) -> Option<&Msg>
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);Sourcepub fn front_mut(&mut self) -> Option<&mut Msg>
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);Sourcepub fn iter(&self) -> Iter<'_, Msg>
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]);Sourcepub fn msg_get_id_lookup(&self, id: MsgId) -> Option<&Msg>
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§
Auto Trait Implementations§
impl Freeze for MsgQueue
impl RefUnwindSafe for MsgQueue
impl Send for MsgQueue
impl Sync for MsgQueue
impl Unpin for MsgQueue
impl UnsafeUnpin for MsgQueue
impl UnwindSafe for MsgQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.