pub struct PolicyContext {
pub user_id: Option<String>,
pub roles: Vec<String>,
pub permissions: Vec<String>,
pub metadata: HashMap<String, String>,
}Expand description
Contextual information available to custom policies that need it.
DomainPolicy methods do NOT take PolicyContext — this struct is
available for custom policy implementations that need richer context
beyond the entity state (e.g. tenant quota checks).
Fields§
§user_id: Option<String>The authenticated user’s ID, if any.
roles: Vec<String>Roles held by the current principal.
permissions: Vec<String>Permissions held by the current principal.
metadata: HashMap<String, String>Arbitrary key-value metadata (tenant id, feature flags, etc.).
Implementations§
Source§impl PolicyContext
impl PolicyContext
pub fn new() -> Self
pub fn with_user(self, user_id: impl Into<String>) -> Self
pub fn with_role(self, role: impl Into<String>) -> Self
pub fn with_permission(self, perm: impl Into<String>) -> Self
pub fn has_role(&self, role: &str) -> bool
pub fn has_permission(&self, perm: &str) -> bool
Trait Implementations§
Source§impl Clone for PolicyContext
impl Clone for PolicyContext
Source§impl Debug for PolicyContext
impl Debug for PolicyContext
Auto Trait Implementations§
impl Freeze for PolicyContext
impl RefUnwindSafe for PolicyContext
impl Send for PolicyContext
impl Sync for PolicyContext
impl Unpin for PolicyContext
impl UnsafeUnpin for PolicyContext
impl UnwindSafe for PolicyContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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 more