wolfrpg_map_parser/command/input_key_command/input_toggle/
state.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
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::command::input_key_command::input_toggle::basic::Basic;
use crate::command::input_key_command::input_toggle::device::Device;
use crate::command::input_key_command::input_toggle::input_type::InputType;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub enum State {
    Basic(Basic),
    Device(Device),
}

impl State {
    pub fn parse(bytes: &[u8], input_type: &InputType) -> (usize, Self) {
        match *input_type {
            InputType::Basic => {
                let (bytes_read, state): (usize, Basic) = Basic::parse(bytes);

                (bytes_read, Self::Basic(state))
            }

            InputType::Device => {
                let (bytes_read, device): (usize, Device) = Device::parse(bytes);

                (bytes_read, Self::Device(device))
            }

            _ => unreachable!(),
        }
    }
}