pub struct Capability<P, R>where
P: Permission,
R: Resource,{ /* private fields */ }Expand description
An unforgeable proof that subject subject holds permission P on resource R.
Construct via PolicyEngine::mint_capability.
The phantom parameters P and R are erased at runtime but enforced at compile time.
Implementations§
Source§impl<P, R> Capability<P, R>where
P: Permission,
R: Resource,
impl<P, R> Capability<P, R>where
P: Permission,
R: Resource,
Sourcepub fn resource_id(&self) -> &str
pub fn resource_id(&self) -> &str
The resource identifier this capability covers.
Sourcepub fn permission_name() -> &'static str
pub fn permission_name() -> &'static str
The permission name (from the type parameter).
Source§impl<P, R> Capability<P, R>where
P: Permission,
R: Resource,
impl<P, R> Capability<P, R>where
P: Permission,
R: Resource,
Sourcepub fn coerce<Q>(self) -> Capability<Q, R>where
Q: Permission,
P: Implies<Q>,
pub fn coerce<Q>(self) -> Capability<Q, R>where
Q: Permission,
P: Implies<Q>,
Downcast this capability to a less-privileged one.
Only callable when P: Implies<Q> — the compiler enforces the lattice.
This is a zero-cost operation: subject and resource are preserved;
only the permission type parameter changes.
§Example
ⓘ
let write_cap: Capability<CanWrite, Report> =
agent.request_capability(&report).await?;
// CanWrite → CanRead is a valid lattice relationship:
let read_cap: Capability<CanRead, Report> = write_cap.coerce();Trait Implementations§
Source§impl<P, R> Debug for Capability<P, R>where
P: Permission,
R: Resource,
impl<P, R> Debug for Capability<P, R>where
P: Permission,
R: Resource,
Auto Trait Implementations§
impl<P, R> Freeze for Capability<P, R>
impl<P, R> RefUnwindSafe for Capability<P, R>
impl<P, R> Send for Capability<P, R>
impl<P, R> Sync for Capability<P, R>
impl<P, R> Unpin for Capability<P, R>
impl<P, R> UnsafeUnpin for Capability<P, R>
impl<P, R> UnwindSafe for Capability<P, R>
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