1use cyfs_base::*;
2use std::str::FromStr;
3
4#[repr(u8)]
6#[derive(Clone, Copy, Debug, Eq, PartialEq, RawEncode, RawDecode)]
7pub enum ZoneRole {
8 ActiveOOD = 0,
9 StandbyOOD = 1,
10 ReservedOOD = 2,
11 Device = 3, }
13
14impl ZoneRole {
15 pub fn is_ood_device(&self) -> bool {
16 match &self {
17 Self::Device => false,
18 _ => true,
19 }
20 }
21
22 pub fn is_active_ood(&self) -> bool {
23 match &self {
24 Self::ActiveOOD => true,
25 _ => false,
26 }
27 }
28
29 pub fn as_str(&self) -> &str {
30 match &self {
31 Self::ActiveOOD => "active-ood",
32 Self::StandbyOOD => "standby-ood",
33 Self::ReservedOOD => "reserved-ood",
34 Self::Device => "device",
35 }
36 }
37}
38
39impl std::fmt::Display for ZoneRole {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(f, "{}", self.as_str())
42 }
43}
44
45
46impl FromStr for ZoneRole {
47 type Err = BuckyError;
48
49 fn from_str(value: &str) -> Result<Self, Self::Err> {
50 let ret = match value {
51 "active-ood" => Self::ActiveOOD,
52 "standby-ood" => Self::StandbyOOD,
53 "reserved-ood" => Self::ReservedOOD,
54 "device" => Self::Device,
55 v @ _ => {
56 let msg = format!("unknown ZoneRole: {}", v);
57 error!("{}", msg);
58
59 return Err(BuckyError::new(BuckyErrorCode::UnSupport, msg));
60 }
61 };
62
63 Ok(ret)
64 }
65}