pub struct Grant {
pub target: GrantTarget,
pub level: PermissionLevel,
pub expires: Option<Instant>,
}Expand description
A permission grant combining a target and permission level.
Grants are the core building blocks of the permission system. Each grant specifies:
- What can be accessed (the target)
- What level of access is permitted (the level)
- When the grant expires (optional)
Fields§
§target: GrantTargetWhat this grant applies to (path, domain, or command).
level: PermissionLevelThe permission level granted.
expires: Option<Instant>Optional expiration time. If None, grant lasts for the session.
Implementations§
Source§impl Grant
impl Grant
Sourcepub fn new(target: GrantTarget, level: PermissionLevel) -> Grant
pub fn new(target: GrantTarget, level: PermissionLevel) -> Grant
Creates a new grant with the given target and level.
The grant has no expiration (session-scoped).
Sourcepub fn with_expiration(
target: GrantTarget,
level: PermissionLevel,
expires: Instant,
) -> Grant
pub fn with_expiration( target: GrantTarget, level: PermissionLevel, expires: Instant, ) -> Grant
Creates a new grant with an expiration time.
Sourcepub fn read_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
pub fn read_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
Creates a read grant for a path.
Sourcepub fn write_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
pub fn write_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
Creates a write grant for a path.
Sourcepub fn execute_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
pub fn execute_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
Creates an execute grant for a path.
Sourcepub fn admin_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
pub fn admin_path(path: impl Into<PathBuf>, recursive: bool) -> Grant
Creates an admin grant for a path.
Sourcepub fn domain(pattern: impl Into<String>, level: PermissionLevel) -> Grant
pub fn domain(pattern: impl Into<String>, level: PermissionLevel) -> Grant
Creates a grant for a network domain.
Sourcepub fn command(pattern: impl Into<String>, level: PermissionLevel) -> Grant
pub fn command(pattern: impl Into<String>, level: PermissionLevel) -> Grant
Creates a grant for a shell command pattern.
Sourcepub fn satisfies(&self, request: &PermissionRequest) -> bool
pub fn satisfies(&self, request: &PermissionRequest) -> bool
Checks if this grant satisfies a permission request.
A grant satisfies a request if:
- The grant’s target covers the request’s target
- The grant’s level satisfies the request’s required level
- The grant has not expired
§Arguments
request- The permission request to check against
§Returns
true if this grant satisfies the request
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Checks if this grant has expired.
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Returns a display-friendly description of this grant.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Grant
impl<'de> Deserialize<'de> for Grant
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Grant, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Grant, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Grant
impl Serialize for Grant
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 Eq for Grant
impl StructuralPartialEq for Grant
Auto Trait Implementations§
impl Freeze for Grant
impl RefUnwindSafe for Grant
impl Send for Grant
impl Sync for Grant
impl Unpin for Grant
impl UnwindSafe for Grant
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> 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> 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> 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 more