pub struct MemoriesState { /* private fields */ }Expand description
Materialized view over the memories log.
Per perf #96, the value type is Arc<Memory> (not Memory).
Query reads (execute, find_many, MemoriesQuery::collect)
hand back Vec<Arc<Memory>> — each match is an atomic
refcount bump instead of a deep Memory clone (which carries
String content, Vec<String> tags, String source — 3+
allocations per cloned entry). Mutations route through
Arc::make_mut so a unique Arc mutates in place (the common
case under the fold’s serial write lock) and a shared Arc
(outstanding reader) clones-on-write to preserve the reader’s
snapshot.
Serialize / Deserialize are derived so the state can be
snapshotted via super::super::CortexAdapter::snapshot and
restored via super::super::CortexAdapter::open_from_snapshot.
Arc<Memory> serializes transparently with serde’s rc
feature (already enabled in this crate’s serde dep).
Implementations§
Source§impl MemoriesState
impl MemoriesState
Sourcepub fn query(&self) -> MemoriesQuery<'_>
pub fn query(&self) -> MemoriesQuery<'_>
Start a fluent query over this state snapshot.
Source§impl MemoriesState
impl MemoriesState
Sourcepub fn new() -> MemoriesState
pub fn new() -> MemoriesState
Create an empty state.
Sourcepub fn get(&self, id: u64) -> Option<&Memory>
pub fn get(&self, id: u64) -> Option<&Memory>
Look up a memory by id. Returns a borrow into the Arc
payload so the common single-read case doesn’t pay a
refcount bump; callers that need an owned share can clone
the Arc themselves via Self::get_arc.
Sourcepub fn get_arc(&self, id: u64) -> Option<Arc<Memory>>
pub fn get_arc(&self, id: u64) -> Option<Arc<Memory>>
Look up a memory by id and return an Arc share. Cheap (atomic refcount bump) — use when the caller needs to hold the memory past the borrow’s lifetime.
Sourcepub fn unpinned(&self) -> impl Iterator<Item = &Memory>
pub fn unpinned(&self) -> impl Iterator<Item = &Memory>
Iterate over memories that are NOT pinned.
Sourcepub fn find_unique(&self, id: u64) -> Option<&Memory>
pub fn find_unique(&self, id: u64) -> Option<&Memory>
Look up a memory by id. Alias of Self::get.
Sourcepub fn find_many(&self, filter: &MemoriesFilter) -> Vec<Arc<Memory>>
pub fn find_many(&self, filter: &MemoriesFilter) -> Vec<Arc<Memory>>
Collect all memories matching filter, respecting order +
limit. Returns Vec<Arc<Memory>> per perf #96 — each
match is one atomic refcount bump instead of the legacy
deep Memory clone.
Sourcepub fn count_where(&self, filter: &MemoriesFilter) -> usize
pub fn count_where(&self, filter: &MemoriesFilter) -> usize
Count memories matching filter. Ignores limit.
Sourcepub fn exists_where(&self, filter: &MemoriesFilter) -> bool
pub fn exists_where(&self, filter: &MemoriesFilter) -> bool
True if any memory matches filter. Short-circuits.
Trait Implementations§
Source§impl Clone for MemoriesState
impl Clone for MemoriesState
Source§fn clone(&self) -> MemoriesState
fn clone(&self) -> MemoriesState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more