wolfrpg_map_parser/command/set_string_command/
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
32
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::command::set_string_command::base::Base;
use crate::command::set_string_command::dynamic::Dynamic;
use crate::command::set_string_command::input::Input;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub enum State {
    Base(Base),
    Dynamic(Dynamic),
    Input(Input),
}

impl State {
    pub fn parse_base(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, Base) = Base::parse(bytes);

        (bytes_read, Self::Base(command))
    }

    pub fn parse_dynamic(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, Dynamic) = Dynamic::parse(bytes);

        (bytes_read, Self::Dynamic(command))
    }

    pub fn parse_input(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, Input) = Input::parse(bytes);

        (bytes_read, Self::Input(command))
    }
}