1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use serde::{Deserialize, Serialize};
use specs::{Component, DerefFlaggedStorage, VecStorage};
use strum::EnumVariantNames;

// EnumVariantNames is used by bins for clap only, but using strum here gets rid
// of the clap dependency
#[derive(
    Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, EnumVariantNames,
)]
pub enum AdminRole {
    Moderator = 0,
    Admin = 1,
}

impl core::str::FromStr for AdminRole {
    type Err = &'static str;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "mod" | "moderator" => Ok(AdminRole::Moderator),
            "admin" => Ok(AdminRole::Admin),
            _ => Err("Could not parse AdminRole"),
        }
    }
}

impl ToString for AdminRole {
    fn to_string(&self) -> String {
        match self {
            AdminRole::Moderator => "moderator",
            AdminRole::Admin => "admin",
        }
        .into()
    }
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Admin(pub AdminRole);

impl Component for Admin {
    type Storage = DerefFlaggedStorage<Self, VecStorage<Self>>;
}