control_code/csi/
disposition.rs

1//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14
15use nom;
16
17#[derive(Eq, PartialEq, Copy, Clone, Debug)]
18pub enum Disposition {
19	ToHome,
20	ToHomeWithLeader,
21	Center,
22	CenterWithLeader,
23	ToLimit,
24	ToLimitWithLeader,
25	ToBoth,
26}
27
28impl Disposition {
29	#[inline]
30	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
31		match value {
32			0 => Ok(Disposition::ToHome),
33			1 => Ok(Disposition::ToHomeWithLeader),
34			2 => Ok(Disposition::Center),
35			3 => Ok(Disposition::CenterWithLeader),
36			4 => Ok(Disposition::ToLimit),
37			5 => Ok(Disposition::ToLimitWithLeader),
38			6 => Ok(Disposition::ToBoth),
39			_ => Err(nom::ErrorKind::Custom(9002)),
40		}
41	}
42}
43
44impl Into<u32> for Disposition {
45	#[inline]
46	fn into(self) -> u32 {
47		match self {
48			Disposition::ToHome            => 0,
49			Disposition::ToHomeWithLeader  => 1,
50			Disposition::Center            => 2,
51			Disposition::CenterWithLeader  => 3,
52			Disposition::ToLimit           => 4,
53			Disposition::ToLimitWithLeader => 5,
54			Disposition::ToBoth            => 6,
55		}
56	}
57}