#[non_exhaustive]pub struct User {
pub id: i64,
pub username: String,
pub nickname: String,
pub email: String,
pub roles: HashSet<String>,
pub permissions: HashSet<String>,
}Expand description
用户信息
标注 #[non_exhaustive]:未来新增字段不构成破坏性变更。
请使用 User::new 构造,再通过字段赋值设置可选属性。
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: i64用户 ID
username: String用户名
nickname: String昵称
email: String邮箱
roles: HashSet<String>角色集合(HashSet 保证 O(1) 查找)
permissions: HashSet<String>权限集合(HashSet 保证 O(1) 查找)
Implementations§
Source§impl User
impl User
Sourcepub fn with_roles(
self,
roles: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_roles( self, roles: impl IntoIterator<Item = impl Into<String>>, ) -> Self
设置角色集合(替换现有角色)
Sourcepub fn with_permissions(
self,
permissions: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_permissions( self, permissions: impl IntoIterator<Item = impl Into<String>>, ) -> Self
设置权限集合(替换现有权限)
Sourcepub fn has_permission(&self, permission: &str) -> bool
pub fn has_permission(&self, permission: &str) -> bool
检查是否有指定权限(O(1) HashSet 查找)
Sourcepub fn has_any_role(&self, roles: &[String]) -> bool
pub fn has_any_role(&self, roles: &[String]) -> bool
检查是否有任一角色(O(1) 每角色)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for User
impl RefUnwindSafe for User
impl Send for User
impl Sync for User
impl Unpin for User
impl UnsafeUnpin for User
impl UnwindSafe for User
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> 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