wolfrpg_map_parser/command/input_key_command/input_toggle/
state.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::command::input_key_command::input_toggle::basic::Basic;
4use crate::command::input_key_command::input_toggle::device::Device;
5use crate::command::input_key_command::input_toggle::input_type::InputType;
6
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8#[derive(PartialEq, Clone)]
9pub enum State {
10    Basic(Basic),
11    Device(Device),
12}
13
14impl State {
15    pub(crate) fn parse(bytes: &[u8], input_type: &InputType) -> (usize, Self) {
16        match *input_type {
17            InputType::Basic => {
18                let (bytes_read, state): (usize, Basic) = Basic::parse(bytes);
19
20                (bytes_read, Self::Basic(state))
21            }
22
23            InputType::Device => {
24                let (bytes_read, device): (usize, Device) = Device::parse(bytes);
25
26                (bytes_read, Self::Device(device))
27            }
28
29            _ => unreachable!(),
30        }
31    }
32}