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