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));Trait Implementations§
Auto Trait Implementations§
impl Freeze for MsgIndex
impl RefUnwindSafe for MsgIndex
impl Send for MsgIndex
impl Sync for MsgIndex
impl Unpin for MsgIndex
impl UnsafeUnpin for MsgIndex
impl UnwindSafe for MsgIndex
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
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>
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>
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.