control_code/csi/
direction.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 Direction {
19	Forward,
20	Backward,
21}
22
23impl Direction {
24	#[inline]
25	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
26		match value {
27			0 => Ok(Direction::Forward),
28			1 => Ok(Direction::Backward),
29			_ => Err(nom::ErrorKind::Custom(9002)),
30		}
31	}
32}
33
34impl Into<u32> for Direction {
35	#[inline]
36	fn into(self) -> u32 {
37		match self {
38			Direction::Forward  => 0,
39			Direction::Backward => 1,
40		}
41	}
42}