pub struct CapabilityConstraints {
pub max_uses: Option<u64>,
pub current_uses: u64,
pub rate_limit: Option<RateLimit>,
pub recent_use_timestamps: Vec<i64>,
pub time_windows: Vec<TimeWindow>,
pub requires_approval: bool,
pub approval_timeout_ms: Option<u64>,
pub custom: HashMap<String, String>,
}Expand description
Constraints on capability usage.
Fields§
§max_uses: Option<u64>Maximum invocations.
current_uses: u64Current usage count.
rate_limit: Option<RateLimit>Rate limit.
recent_use_timestamps: Vec<i64>Recent usage timestamps for rate limit enforcement (Unix ms). Entries older than the rate limit period are pruned on check.
time_windows: Vec<TimeWindow>Time windows when capability is valid.
requires_approval: boolRequired approval for each use.
approval_timeout_ms: Option<u64>Approval timeout in milliseconds.
custom: HashMap<String, String>Custom constraints as key-value pairs.
Implementations§
Source§impl CapabilityConstraints
impl CapabilityConstraints
Sourcepub fn with_max_uses(self, max: u64) -> Self
pub fn with_max_uses(self, max: u64) -> Self
Set max uses.
Sourcepub fn with_rate_limit(self, limit: RateLimit) -> Self
pub fn with_rate_limit(self, limit: RateLimit) -> Self
Set rate limit.
Sourcepub fn with_time_window(self, window: TimeWindow) -> Self
pub fn with_time_window(self, window: TimeWindow) -> Self
Add a time window.
Sourcepub fn with_requires_approval(self, timeout: Duration) -> Self
pub fn with_requires_approval(self, timeout: Duration) -> Self
Require approval for each use.
Sourcepub fn with_custom(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_custom( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a custom constraint.
Sourcepub fn approval_timeout(&self) -> Option<Duration>
pub fn approval_timeout(&self) -> Option<Duration>
Get approval timeout as Duration.
Sourcepub fn is_usage_limit_reached(&self) -> bool
pub fn is_usage_limit_reached(&self) -> bool
Check if usage limit is reached.
Sourcepub fn increment_usage(&mut self) -> Result<()>
pub fn increment_usage(&mut self) -> Result<()>
Increment usage count. Returns error if limit reached.
Sourcepub fn is_rate_limited(&self, now: i64) -> bool
pub fn is_rate_limited(&self, now: i64) -> bool
Check if the rate limit is exceeded at the given timestamp.
Returns true if the number of recent uses within the rate limit
period meets or exceeds max_requests.
Sourcepub fn record_rate_limit_use(&mut self, now: i64)
pub fn record_rate_limit_use(&mut self, now: i64)
Record a usage for rate limiting purposes.
Prunes timestamps older than the rate limit window.
Trait Implementations§
Source§impl Clone for CapabilityConstraints
impl Clone for CapabilityConstraints
Source§fn clone(&self) -> CapabilityConstraints
fn clone(&self) -> CapabilityConstraints
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CapabilityConstraints
impl Debug for CapabilityConstraints
Source§impl Default for CapabilityConstraints
impl Default for CapabilityConstraints
Source§fn default() -> CapabilityConstraints
fn default() -> CapabilityConstraints
Source§impl<'de> Deserialize<'de> for CapabilityConstraints
impl<'de> Deserialize<'de> for CapabilityConstraints
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CapabilityConstraints
impl RefUnwindSafe for CapabilityConstraints
impl Send for CapabilityConstraints
impl Sync for CapabilityConstraints
impl Unpin for CapabilityConstraints
impl UnwindSafe for CapabilityConstraints
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.