control_code/csi/
unit.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 Unit {
19	Character,
20	Millimeter,
21	ComputerDecipoint,
22	Decidot,
23	Mil,
24	BasicMeasuringUnit,
25	Micrometer,
26	Pixel,
27	Decipoint,
28}
29
30impl Unit {
31	#[inline]
32	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
33		match value {
34			0 => Ok(Unit::Character),
35			1 => Ok(Unit::Millimeter),
36			2 => Ok(Unit::ComputerDecipoint),
37			3 => Ok(Unit::Decidot),
38			4 => Ok(Unit::Mil),
39			5 => Ok(Unit::BasicMeasuringUnit),
40			6 => Ok(Unit::Micrometer),
41			7 => Ok(Unit::Pixel),
42			8 => Ok(Unit::Decipoint),
43			_ => Err(nom::ErrorKind::Custom(9002)),
44		}
45	}
46}
47
48impl Into<u32> for Unit {
49	#[inline]
50	fn into(self) -> u32 {
51		match self {
52			Unit::Character          => 0,
53			Unit::Millimeter         => 1,
54			Unit::ComputerDecipoint  => 2,
55			Unit::Decidot            => 3,
56			Unit::Mil                => 4,
57			Unit::BasicMeasuringUnit => 5,
58			Unit::Micrometer         => 6,
59			Unit::Pixel              => 7,
60			Unit::Decipoint          => 8,
61		}
62	}
63}