pub struct TimedCap<P: Permission> { /* private fields */ }Expand description
A time-bounded capability token proving the holder has permission P.
Created via TimedCap::new, which consumes a Cap<P> and a TTL duration.
After the TTL elapses, try_cap() returns
Err(CapSecError::Expired).
!Send + !Sync by default — use make_send for
cross-thread transfer. Cloning copies the same expiry instant.
Implementations§
Source§impl<P: Permission> TimedCap<P>
impl<P: Permission> TimedCap<P>
Sourcepub fn new(_cap: Cap<P>, ttl: Duration) -> Self
pub fn new(_cap: Cap<P>, ttl: Duration) -> Self
Creates a time-bounded capability by consuming a Cap<P> as proof of possession.
The capability expires after ttl has elapsed from the moment of creation.
Sourcepub fn try_cap(&self) -> Result<Cap<P>, CapSecError>
pub fn try_cap(&self) -> Result<Cap<P>, CapSecError>
Attempts to obtain a Cap<P> from this timed capability.
Returns Ok(Cap<P>) if the TTL has not elapsed, or Err(CapSecError::Expired)
if the capability has expired.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Advisory check — returns true if the capability has not yet expired.
The result is immediately stale; do not use for control flow.
Always use try_cap for actual access.
Sourcepub fn remaining(&self) -> Duration
pub fn remaining(&self) -> Duration
Returns the remaining duration before expiry.
Returns Duration::ZERO if the capability has already expired.
Sourcepub fn make_send(self) -> TimedSendCap<P>
pub fn make_send(self) -> TimedSendCap<P>
Converts this capability into a TimedSendCap that can cross thread boundaries.
This is an explicit opt-in — you’re acknowledging that this capability will be used in a multi-threaded context.