pub struct Scope { /* private fields */ }Expand description
A validated capability scope in service:resource:action form.
Serializes as a plain string, so the wire representation is a flat array of strings rather than a nested structure.
§Examples
use agent_capability_token::Scope;
let scope: Scope = "tools:calendar:invoke".parse()?;
assert_eq!(scope.service(), "tools");
assert_eq!(scope.action(), "invoke");
// A granted wildcard covers a specific request.
let granted: Scope = "runtime:platform:*".parse()?;
let requested: Scope = "runtime:platform:spawn".parse()?;
assert!(granted.covers(&requested));Implementations§
Source§impl Scope
impl Scope
Sourcepub fn parse(value: impl Into<String>) -> ActResult<Self>
pub fn parse(value: impl Into<String>) -> ActResult<Self>
Parses and validates a scope string.
§Errors
Returns ActError::MalformedScope unless the input has exactly three
non-empty colon-separated segments.
Sourcepub fn covers(&self, requested: &Self) -> bool
pub fn covers(&self, requested: &Self) -> bool
Whether this scope, treated as a grant, authorizes requested.
A WILDCARD segment in the grant matches any value in the same
position. The comparison is directional: a wildcard in requested is
matched literally, so a caller cannot widen its own authority by asking
for *.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Scope
impl<'de> Deserialize<'de> for Scope
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
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,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Scope
impl PartialOrd for Scope
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
Mutably borrows from an owned value. Read more