pub struct SessionPermissionCache { /* private fields */ }Expand description
会话级权限缓存 — 记录用户 “always” 决策。
§设计参考
- Oh-My-Pi:
Map<string, "allow_always" | "reject_always"> - OpenCode:
approved: Ruleset累积规则 - katu:
Ruleset子集,只包含 Session 来源的 allow/deny 规则
§线程安全
作为纯数据结构,线程安全由持有者负责(如 Arc<RwLock<SessionPermissionCache>>)。
§Examples
use katu_core::permission::*;
let mut cache = SessionPermissionCache::new();
// 用户选择 "always allow bash(git *)"
cache.allow_always("bash", "git *");
// 下次检查时命中缓存
assert_eq!(cache.check("bash", "git pull"), Some(PermissionBehavior::Allow));
assert_eq!(cache.check("bash", "rm -rf /"), None); // 不在缓存中Implementations§
Source§impl SessionPermissionCache
impl SessionPermissionCache
Sourcepub fn allow_always(
&mut self,
permission: impl Into<String>,
pattern: impl Into<String>,
)
pub fn allow_always( &mut self, permission: impl Into<String>, pattern: impl Into<String>, )
记录 “always allow”。
Sourcepub fn deny_always(
&mut self,
permission: impl Into<String>,
pattern: impl Into<String>,
)
pub fn deny_always( &mut self, permission: impl Into<String>, pattern: impl Into<String>, )
记录 “always deny”。
Sourcepub fn check(
&self,
permission_key: &str,
content: &str,
) -> Option<PermissionBehavior>
pub fn check( &self, permission_key: &str, content: &str, ) -> Option<PermissionBehavior>
检查缓存 — 返回匹配的缓存决策。
使用 last-match-wins 语义。
Sourcepub fn to_ruleset(&self) -> Ruleset
pub fn to_ruleset(&self) -> Ruleset
转换为可持久化的 Ruleset(Session 来源)。
Trait Implementations§
Source§impl Clone for SessionPermissionCache
impl Clone for SessionPermissionCache
Source§fn clone(&self) -> SessionPermissionCache
fn clone(&self) -> SessionPermissionCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SessionPermissionCache
impl Debug for SessionPermissionCache
Source§impl Default for SessionPermissionCache
impl Default for SessionPermissionCache
Source§fn default() -> SessionPermissionCache
fn default() -> SessionPermissionCache
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for SessionPermissionCache
impl<'de> Deserialize<'de> for SessionPermissionCache
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SessionPermissionCache
impl RefUnwindSafe for SessionPermissionCache
impl Send for SessionPermissionCache
impl Sync for SessionPermissionCache
impl Unpin for SessionPermissionCache
impl UnsafeUnpin for SessionPermissionCache
impl UnwindSafe for SessionPermissionCache
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