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) -> Self
pub fn new(target: GrantTarget, level: PermissionLevel) -> Self
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,
) -> Self
pub fn with_expiration( target: GrantTarget, level: PermissionLevel, expires: Instant, ) -> Self
Creates a new grant with an expiration time.
Sourcepub fn read_path(path: impl Into<PathBuf>, recursive: bool) -> Self
pub fn read_path(path: impl Into<PathBuf>, recursive: bool) -> Self
Creates a read grant for a path.
Sourcepub fn write_path(path: impl Into<PathBuf>, recursive: bool) -> Self
pub fn write_path(path: impl Into<PathBuf>, recursive: bool) -> Self
Creates a write grant for a path.
Sourcepub fn execute_path(path: impl Into<PathBuf>, recursive: bool) -> Self
pub fn execute_path(path: impl Into<PathBuf>, recursive: bool) -> Self
Creates an execute grant for a path.
Sourcepub fn admin_path(path: impl Into<PathBuf>, recursive: bool) -> Self
pub fn admin_path(path: impl Into<PathBuf>, recursive: bool) -> Self
Creates an admin grant for a path.
Sourcepub fn domain(pattern: impl Into<String>, level: PermissionLevel) -> Self
pub fn domain(pattern: impl Into<String>, level: PermissionLevel) -> Self
Creates a grant for a network domain.
Sourcepub fn command(pattern: impl Into<String>, level: PermissionLevel) -> Self
pub fn command(pattern: impl Into<String>, level: PermissionLevel) -> Self
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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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§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.