lf2_parse/element/w_point/
w_point_kind.rs

1use std::str::FromStr;
2
3use crate::WPointKindParseError;
4
5/// Whether this describes holding a weapon, held as one, or dropping one.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum WPointKind {
8    /// Indicates the information when holding a weapon.
9    Holding = 1,
10    /// Indicates the coordinates when held as a weapon.
11    Held = 2,
12    /// Indicates a held weapon should be dropped.
13    Dropping = 3,
14}
15
16impl Default for WPointKind {
17    fn default() -> Self {
18        Self::Holding
19    }
20}
21
22impl FromStr for WPointKind {
23    type Err = WPointKindParseError;
24
25    fn from_str(s: &str) -> Result<WPointKind, WPointKindParseError> {
26        s.parse::<u32>()
27            .map_err(WPointKindParseError::ParseIntError)
28            .and_then(|value| match value {
29                1 => Ok(WPointKind::Holding),
30                2 => Ok(WPointKind::Held),
31                3 => Ok(WPointKind::Dropping),
32                value => Err(WPointKindParseError::InvalidValue(value)),
33            })
34    }
35}