pub struct MsgIndex { /* private fields */ }Expand description
Owning index of Msg values keyed on MsgId.
The C engine stores struct msg * pointers; the Rust port owns
the value directly so dropping the index releases every contained
message. Lookups return references; transferring ownership out of
the index requires MsgIndex::remove.
§Thread safety
MsgIndex mirrors the reference engine’s outstanding_msgs_dict,
which is per-connection and accessed only from the connection’s
owning event-loop thread. The Rust port preserves that
single-threaded contract: MsgIndex is Send (it can be moved
to another task or thread, e.g. when a connection migrates) but
is intentionally not exposed through any synchronisation
primitive. The wrapped std::collections::HashMap inside
DictMap is not Sync, so two
tasks cannot share a &MsgIndex and call its mutating methods
concurrently. Stages 9 and beyond keep the index private to the
per-connection FSM; if a future caller ever needs cross-thread
shared access, that caller is responsible for wrapping it in a
Mutex (or equivalent), not the type itself.
Implementations§
Source§impl MsgIndex
impl MsgIndex
Sourcepub fn new() -> Self
pub fn new() -> Self
Build an empty index.
§Examples
use dynomite::msg::MsgIndex;
let idx = MsgIndex::new();
assert!(idx.is_empty());Sourcepub fn insert(&mut self, msg: Msg) -> Option<Msg>
pub fn insert(&mut self, msg: Msg) -> Option<Msg>
Insert msg under its own id. The previous value, if any, is
returned to the caller.
§Examples
use dynomite::msg::{Msg, MsgIndex, MsgType};
let mut idx = MsgIndex::new();
let m = Msg::new(7, MsgType::ReqRedisGet, true);
assert!(idx.insert(m).is_none());
assert!(idx.contains_key(7));Sourcepub fn remove(&mut self, id: MsgId) -> Option<Msg>
pub fn remove(&mut self, id: MsgId) -> Option<Msg>
Remove the message stored under id and transfer ownership
to the caller.
§Examples
use dynomite::msg::{Msg, MsgIndex, MsgType};
let mut idx = MsgIndex::new();
idx.insert(Msg::new(7, MsgType::ReqRedisGet, true));
assert!(idx.remove(7).is_some());
assert!(idx.remove(7).is_none());Sourcepub fn get(&self, id: MsgId) -> Option<&Msg>
pub fn get(&self, id: MsgId) -> Option<&Msg>
Borrow the message stored under id, if any.
§Examples
use dynomite::msg::{Msg, MsgIndex, MsgType};
let mut idx = MsgIndex::new();
idx.insert(Msg::new(7, MsgType::ReqRedisGet, true));
assert_eq!(idx.get(7).unwrap().id(), 7);Sourcepub fn get_mut(&mut self, id: MsgId) -> Option<&mut Msg>
pub fn get_mut(&mut self, id: MsgId) -> Option<&mut Msg>
Mutably borrow the message stored under id.
§Examples
use dynomite::msg::{Msg, MsgIndex, MsgType};
let mut idx = MsgIndex::new();
idx.insert(Msg::new(7, MsgType::ReqRedisGet, true));
idx.get_mut(7).unwrap().set_done(true);Sourcepub fn contains_key(&self, id: MsgId) -> bool
pub fn contains_key(&self, id: MsgId) -> bool
True when an entry exists for id.
§Examples
use dynomite::msg::MsgIndex;
assert!(!MsgIndex::new().contains_key(0));