wolfrpg_map_parser/command/set_variable_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
use crate::command::set_variable_command::base::Base;
use crate::command::set_variable_command::range::Range;
#[cfg(feature = "serde")]
use serde::Serialize;

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

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_range(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, Range)
            = Range::parse(bytes);

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