- Add #![allow(dead_code)] to modules with future features - Fix trailing whitespace in main.rs - Remove unused imports (Claims, ObjectId, Deserialize, Serialize) - Fix unnecessary map_err in health_stats.rs - Add allow attributes for experimental and redundant code - Fix redundant pattern matching in health.rs
45 lines
1 KiB
Rust
45 lines
1 KiB
Rust
#![allow(dead_code)]
|
|
use serde::{Deserialize, Serialize};
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum Permission {
|
|
Read,
|
|
Write,
|
|
Delete,
|
|
Share,
|
|
Admin,
|
|
}
|
|
|
|
impl fmt::Display for Permission {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::Read => write!(f, "read"),
|
|
Self::Write => write!(f, "write"),
|
|
Self::Delete => write!(f, "delete"),
|
|
Self::Share => write!(f, "share"),
|
|
Self::Admin => write!(f, "admin"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Permission {
|
|
pub fn can_read(&self) -> bool {
|
|
matches!(self, Self::Read | Self::Admin)
|
|
}
|
|
|
|
pub fn can_write(&self) -> bool {
|
|
matches!(self, Self::Write | Self::Admin)
|
|
}
|
|
|
|
pub fn can_delete(&self) -> bool {
|
|
matches!(self, Self::Delete | Self::Admin)
|
|
}
|
|
|
|
pub fn can_share(&self) -> bool {
|
|
matches!(self, Self::Share | Self::Admin)
|
|
}
|
|
}
|
|
|
|
pub type Permissions = Vec<Permission>;
|