pub struct MemorySlot {
pub predicate: CanonicalPredicate,
pub state_key: String,
}Expand description
A mapping from a memory predicate to the governed State slot it fills.
Fields§
§predicate: CanonicalPredicateThe canonical predicate to look for, e.g. dietary_identity.
state_key: StringThe State key to fill, e.g. user:diet.
Implementations§
Source§impl MemorySlot
impl MemorySlot
Sourcepub fn new(predicate: impl AsRef<str>, state_key: impl Into<String>) -> Self
pub fn new(predicate: impl AsRef<str>, state_key: impl Into<String>) -> Self
Map predicate onto state_key.
The key must use the platform’s scope:key convention — user:diet,
not user.diet. The gates themselves do not care: needs, requires
and Guard::is_set route through State::contains, which treats the key
as an opaque string. What the colon buys is composition with the prefix
scopes, so state.user().get::<String>("diet") finds the slot. A dotted
key would read back None there — silently, for a developer doing
exactly what the platform documentation says.
That is a programming error knowable at construction, so this panics
on a malformed key rather than documenting the trap and handing it over.
Use try_new where the key is not a literal.
The predicate is not checked against the corpus: a slot naming a fact the user has not stated yet is the normal case, and for a brand-new user every slot is.
MemorySlot::new("dietary_identity", "user:diet"); // fine
assert!(MemorySlot::try_new("dietary_identity", "user.diet").is_err());
assert!(MemorySlot::try_new("dietary_identity", "derived:diet").is_err());Sourcepub fn try_new(
predicate: impl AsRef<str>,
state_key: impl Into<String>,
) -> Result<Self, MemorySlotError>
pub fn try_new( predicate: impl AsRef<str>, state_key: impl Into<String>, ) -> Result<Self, MemorySlotError>
new without the panic, for keys built at runtime.
Use this when the slot comes from configuration or user input; use
new for the literals in application code, where a bad key is a
programming error worth failing on immediately.
Trait Implementations§
Source§impl Clone for MemorySlot
impl Clone for MemorySlot
Source§fn clone(&self) -> MemorySlot
fn clone(&self) -> MemorySlot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MemorySlot
impl Debug for MemorySlot
Source§impl PartialEq for MemorySlot
impl PartialEq for MemorySlot
impl StructuralPartialEq for MemorySlot
Auto Trait Implementations§
impl Freeze for MemorySlot
impl RefUnwindSafe for MemorySlot
impl Send for MemorySlot
impl Sync for MemorySlot
impl Unpin for MemorySlot
impl UnwindSafe for MemorySlot
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,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].