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
//! For sending messages to i3
#[derive(Eq, PartialEq, Hash, Debug, Clone, Copy)]
pub enum Msg {
    RunCommand,
    Workspaces,
    Subscribe,
    Outputs,
    Tree,
    Marks,
    BarConfig,
    Version,
    BindingModes,
    Config,
    Tick,
    Sync,
}

impl From<u32> for Msg {
    fn from(num: u32) -> Self {
        match num {
            0 => Msg::RunCommand,
            1 => Msg::Workspaces,
            2 => Msg::Subscribe,
            3 => Msg::Outputs,
            4 => Msg::Tree,
            5 => Msg::Marks,
            6 => Msg::BarConfig,
            7 => Msg::Version,
            8 => Msg::BindingModes,
            9 => Msg::Config,
            10 => Msg::Tick,
            11 => Msg::Sync,
            _ => panic!("Unknown message type found"),
        }
    }
}

impl From<Msg> for u32 {
    fn from(msg: Msg) -> Self {
        match msg {
            Msg::RunCommand => 0,
            Msg::Workspaces => 1,
            Msg::Subscribe => 2,
            Msg::Outputs => 3,
            Msg::Tree => 4,
            Msg::Marks => 5,
            Msg::BarConfig => 6,
            Msg::Version => 7,
            Msg::BindingModes => 8,
            Msg::Config => 9,
            Msg::Tick => 10,
            Msg::Sync => 11,
        }
    }
}