pub struct UserContext {
pub user_id: String,
pub email: Option<String>,
pub roles: Vec<String>,
pub permissions: Vec<String>,
pub metadata: Value,
}Expand description
User context extracted from requests
Fields§
§user_id: StringUser ID
email: Option<String>User email
roles: Vec<String>User roles
permissions: Vec<String>User permissions
metadata: ValueCustom metadata
Implementations§
Source§impl UserContext
impl UserContext
Sourcepub fn with_email(self, email: String) -> Self
pub fn with_email(self, email: String) -> Self
Set email
Sourcepub fn with_roles(self, roles: Vec<String>) -> Self
pub fn with_roles(self, roles: Vec<String>) -> Self
Add roles
Sourcepub fn with_permission(self, permission: String) -> Self
pub fn with_permission(self, permission: String) -> Self
Add a permission
Sourcepub fn with_permissions(self, permissions: Vec<String>) -> Self
pub fn with_permissions(self, permissions: Vec<String>) -> Self
Add permissions
Sourcepub fn with_metadata(self, metadata: Value) -> Self
pub fn with_metadata(self, metadata: Value) -> Self
Set metadata
Trait Implementations§
Source§impl AuthUser for UserContext
impl AuthUser for UserContext
Source§fn has_permission(&self, permission: &str) -> bool
fn has_permission(&self, permission: &str) -> bool
Check if user has a permission
Source§fn has_any_role(&self, roles: &[&str]) -> bool
fn has_any_role(&self, roles: &[&str]) -> bool
Check if user has any of the roles
Source§fn has_all_roles(&self, roles: &[&str]) -> bool
fn has_all_roles(&self, roles: &[&str]) -> bool
Check if user has all roles
Source§impl Clone for UserContext
impl Clone for UserContext
Source§fn clone(&self) -> UserContext
fn clone(&self) -> UserContext
Returns a duplicate of the value. Read more
1.0.0 · 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 UserContext
impl Debug for UserContext
Source§impl<'de> Deserialize<'de> for UserContext
impl<'de> Deserialize<'de> for UserContext
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 UserContext
impl RefUnwindSafe for UserContext
impl Send for UserContext
impl Sync for UserContext
impl Unpin for UserContext
impl UnwindSafe for UserContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging