ed_journals/modules/status/models/
gui_focus.rs

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use serde::Serialize;
use std::str::FromStr;
use thiserror::Error;

use crate::deserialize_in_order_impl;

#[derive(Debug, Serialize, PartialEq, Eq, Clone)]
pub enum GuiFocus {
    NoFocus,
    InternalPanel,
    ExternalPanel,
    CommsPanel,
    RolePanel,
    StationServices,
    GalaxyMap,
    SystemMap,
    Orrery,
    FSSMode,
    SAAMode,
    Codex,
}

#[derive(Debug, Error)]
pub enum GuiFocusError {
    #[error("Unknown value for GUI focus: {0}")]
    UnknownValue(u8),

    #[error("Unknown string value for GUI focus: '{0}'")]
    UnknownStringValue(String),
}

impl TryFrom<u8> for GuiFocus {
    type Error = GuiFocusError;

    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Ok(match value {
            0 => GuiFocus::NoFocus,
            1 => GuiFocus::InternalPanel,
            2 => GuiFocus::ExternalPanel,
            3 => GuiFocus::CommsPanel,
            4 => GuiFocus::RolePanel,
            5 => GuiFocus::StationServices,
            6 => GuiFocus::GalaxyMap,
            7 => GuiFocus::SystemMap,
            8 => GuiFocus::Orrery,
            9 => GuiFocus::FSSMode,
            10 => GuiFocus::SAAMode,
            11 => GuiFocus::Codex,
            _ => return Err(GuiFocusError::UnknownValue(value)),
        })
    }
}

impl FromStr for GuiFocus {
    type Err = GuiFocusError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "NoFocus" => GuiFocus::NoFocus,
            "InternalPanel" => GuiFocus::InternalPanel,
            "ExternalPanel" => GuiFocus::ExternalPanel,
            "CommsPanel" => GuiFocus::CommsPanel,
            "RolePanel" => GuiFocus::RolePanel,
            "StationServices" => GuiFocus::StationServices,
            "GalaxyMap" => GuiFocus::GalaxyMap,
            "SystemMap" => GuiFocus::SystemMap,
            "Orrery" => GuiFocus::Orrery,
            "FSSMode" => GuiFocus::FSSMode,
            "SAAMode" => GuiFocus::SAAMode,
            "Codex" => GuiFocus::Codex,
            _ => return Err(GuiFocusError::UnknownStringValue(s.to_string())),
        })
    }
}

deserialize_in_order_impl!(
    GuiFocus =>
        A ? u8,
        B # String,
);