pub struct Scope(/* private fields */);Expand description
A partition key for multi-agent / multi-tenant isolation.
Scope is a thin newtype around SmolStr (inline up to 23 bytes — most
scope identifiers fit). Two scopes compare equal iff their string forms
match byte-for-byte. There is no implicit fallback to a “default”
scope — a Scope must be constructed explicitly.
§Validation
The string must match ^[A-Za-z0-9_\-.]{1,128}$. This is enforced by
Scope::new; the unchecked constructor is pub(crate) and only used by
trusted internal call sites (deserialization of validated wire data).
§Examples
use lunaris_core::Scope;
let s = Scope::new("acme.agent-42").unwrap();
assert_eq!(s.as_str(), "acme.agent-42");Implementations§
Source§impl Scope
impl Scope
Sourcepub fn new(s: impl AsRef<str>) -> Result<Scope, ScopeError>
pub fn new(s: impl AsRef<str>) -> Result<Scope, ScopeError>
Construct a Scope from s, enforcing the validation regex
^[A-Za-z0-9_\-.]{1,128}$.
Returns Err(ScopeError::Invalid) on empty string, string longer than
128 bytes, or any character outside the allowed set.
Sourcepub fn is_valid_segment(segment: &str) -> bool
pub fn is_valid_segment(segment: &str) -> bool
Is segment a legal sub-partition segment?
A segment is a non-empty run of [A-Za-z0-9_-]. Note . is EXCLUDED
here even though Scope::new permits it in a whole scope, because
. is the level separator (see child): a segment
carrying its own . would forge an extra level. : and / are
likewise excluded so a composed segment can never byte-alias the
lunaris:{scope}:{kind}:{ulid} KV format.
Sourcepub fn child(&self, segment: &str) -> Result<Scope, ScopeError>
pub fn child(&self, segment: &str) -> Result<Scope, ScopeError>
Compose a child sub-partition by appending a validated .{segment}.
segment must satisfy is_valid_segment;
the full composed string is then re-validated by Scope::new
(alphabet + 128-byte cap). Consequently self.as_str() is ALWAYS a
byte-prefix of the returned child — this is the load-bearing isolation
guarantee for multi-level memory (RFC 0001 sub-partitions): a caller
can only NARROW into a sub-partition of its own scope, never escape to
a sibling or parent.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Scope
RC-4 (v0.2 release-gate review): re-validate on the wire boundary.
impl<'de> Deserialize<'de> for Scope
RC-4 (v0.2 release-gate review): re-validate on the wire boundary.
The previous derived Deserialize with #[serde(transparent)] accepted
any string, bypassing Scope::new’s regex. Internal deserialization
sites (rows fetched from a future cloud-API backend, MQ envelopes that
gain a scope field, etc.) would have trusted attacker-controlled bytes.
This impl forces every wire-side Scope to clear Scope::new.
Source§fn deserialize<D>(d: D) -> Result<Scope, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<Scope, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for Scope
Source§impl Ord for Scope
impl Ord for Scope
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Scope
impl PartialOrd for Scope
Source§impl Serialize for Scope
impl Serialize for Scope
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Scope
Auto Trait Implementations§
impl Freeze for Scope
impl RefUnwindSafe for Scope
impl Send for Scope
impl Sync for Scope
impl Unpin for Scope
impl UnsafeUnpin for Scope
impl UnwindSafe for Scope
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> EncodedChars for T
impl<T> EncodedChars for T
Source§fn encoding(&self) -> *mut OnigEncodingTypeST
fn encoding(&self) -> *mut OnigEncodingTypeST
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.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<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.