cyfs_lib/base/
zone.rs

1use cyfs_base::*;
2
3use std::fmt;
4use std::str::FromStr;
5
6
7#[derive(Debug, Clone, Eq, PartialEq)]
8pub enum ZoneDirection {
9    LocalToLocal,
10    LocalToRemote,
11    RemoteToLocal,
12}
13
14impl ZoneDirection {
15    fn as_string(&self) -> &str {
16        match *self {
17            ZoneDirection::LocalToLocal => "local_to_local",
18            ZoneDirection::LocalToRemote => "local_to_remote",
19            ZoneDirection::RemoteToLocal => "remote_to_local",
20        }
21    }
22}
23
24
25impl fmt::Display for ZoneDirection {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        fmt::Display::fmt(self.as_string(), f)
28    }
29}
30
31
32impl FromStr for ZoneDirection {
33    type Err = BuckyError;
34
35    fn from_str(value: &str) -> Result<Self, Self::Err> {
36        let ret = match value {
37            "local_to_local" => ZoneDirection::LocalToLocal,
38            "local_to_remote" => ZoneDirection::LocalToRemote,
39            "remote_to_local" => ZoneDirection::RemoteToLocal,
40            v @ _ => {
41                let msg = format!("unknown zone direction: {}", v);
42                error!("{}", msg);
43
44                return Err(BuckyError::from(msg));
45            }
46        };
47
48        Ok(ret)
49    }
50}
51
52