pub struct Namespace { /* private fields */ }Expand description
Hierarchical key prefix for memory operations.
tenant_id segments out per-customer data. scope adds nested
dimensions — typically [agent_id, conversation_id] for chat-style
agents.
Implementations§
Source§impl Namespace
impl Namespace
Sourcepub const fn new(tenant_id: TenantId) -> Self
pub const fn new(tenant_id: TenantId) -> Self
Build a namespace bound to tenant_id. The mandatory argument
is the F2 mitigation in code form — there is no other way to
obtain a Namespace. The TenantId argument has already
passed its validating constructor, so cross-tenant collapse
(":scope" instead of "acme:scope") is structurally
impossible at this surface.
Sourcepub fn with_scope(self, segment: impl Into<String>) -> Self
pub fn with_scope(self, segment: impl Into<String>) -> Self
Append one scope segment. Builder-style.
Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Render the namespace as a flat :-separated key, useful for
backends that take a single string per row. Segments
containing : or \ are escaped (\: and \\) so two
distinct namespaces can never collide on the rendered key.
Sourcepub fn parse(rendered: &str) -> Result<Self>
pub fn parse(rendered: &str) -> Result<Self>
Inverse of Self::render. Decodes a flat :-separated
key back into a typed Namespace, honouring the same
escape rules (\: for : inside a segment, \\ for \).
Round-trip property: Namespace::parse(&ns.render()) == Ok(ns.clone()) for every well-formed namespace.
The motivating consumer is the audit channel (invariant
#18): GraphEvent::MemoryRecall::namespace_key carries
rendered keys, and operators replaying the log recover the
typed scope (tenant boundary, agent / conversation
dimensions) by parsing.
Rejects:
- leading
:(e.g.":scope") — empty tenant component, surfaces asError::InvalidRequestvia theTenantId::try_fromvalidator. Invariant 11 — a tenantlessNamespacewould silently collapse every tenant onto a single rendered key prefix. - trailing lone
\(incomplete escape) — surfaces asError::InvalidRequest. \<x>forxother than:or\— unknown escape, same error variant. Round-tripping a namespace that never contained:or\cannot produce these inputs; they only arise from hand-crafted (invalid) keys.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Namespace
impl<'de> Deserialize<'de> for Namespace
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&Namespace> for NamespacePrefix
impl From<&Namespace> for NamespacePrefix
impl Eq for Namespace
impl StructuralPartialEq for Namespace
Auto Trait Implementations§
impl Freeze for Namespace
impl RefUnwindSafe for Namespace
impl Send for Namespace
impl Sync for Namespace
impl Unpin for Namespace
impl UnsafeUnpin for Namespace
impl UnwindSafe for Namespace
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.