cyfs_lib/base/
front.rs

1use cyfs_base::*;
2
3#[derive(Clone, Copy, Eq, PartialEq, Debug)]
4pub enum BrowserSanboxMode {
5    Forbidden,
6    Strict,
7    Relaxed,
8    None,
9}
10
11impl Default for BrowserSanboxMode {
12    fn default() -> Self {
13        Self::Strict
14    }
15}
16
17impl BrowserSanboxMode {
18    pub fn as_str(&self) -> &str {
19        match *self {
20            Self::Forbidden => "forbidden",
21            Self::Strict => "strict",
22            Self::Relaxed => "relaxed",
23            Self::None => "none",
24        }
25    }
26}
27
28impl std::str::FromStr for BrowserSanboxMode {
29    type Err = BuckyError;
30    fn from_str(s: &str) -> Result<Self, Self::Err> {
31        let mode = match s {
32            "forbidden" => Self::Forbidden,
33            "strict" => Self::Strict,
34            "relaxed" => Self::Relaxed,
35            "none" => Self::None,
36            _ => {
37                let msg = format!("unknown browser mode: {}", s);
38                warn!("{}", msg);
39                return Err(BuckyError::new(BuckyErrorCode::InvalidData, msg));
40            }
41        };
42        Ok(mode)
43    }
44}