manas_http/header/wac_allow/
permission_group.rs

1use std::{ops::Deref, str::FromStr};
2
3use crate::field::rules::alpha::Alpha;
4
5/// A type to represent `permission-group` abnf production fro WAC.
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct PermissionGroup(Alpha);
8
9impl FromStr for PermissionGroup {
10    type Err = InvalidEncodedPermissionGroup;
11
12    fn from_str(s: &str) -> Result<Self, Self::Err> {
13        Ok(Self(s.parse().map_err(|_| InvalidEncodedPermissionGroup)?))
14    }
15}
16
17/// Invalid encoded permission group.
18#[derive(Debug, thiserror::Error)]
19#[error("Invalid encoded permission group.")]
20pub struct InvalidEncodedPermissionGroup;
21
22impl Deref for PermissionGroup {
23    type Target = str;
24
25    fn deref(&self) -> &Self::Target {
26        self.0.as_ref()
27    }
28}
29
30impl PermissionGroup {
31    /// `user` permission group.
32    pub const USER: Self = Self(Alpha::new_small_unchecked("user"));
33
34    /// `public` permission group.
35    pub const PUBLIC: Self = Self(Alpha::new_small_unchecked("public"));
36}