control_code/csi/
parallel.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 Parallel {
19	End,
20	Start,
21	StartSupplementary,
22	StartPhoneticJapanese,
23	StartPhoneticChinese,
24	StopPhonetic,
25}
26
27impl Parallel {
28	#[inline]
29	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
30		match value {
31			0 => Ok(Parallel::End),
32			1 => Ok(Parallel::Start),
33			2 => Ok(Parallel::StartSupplementary),
34			3 => Ok(Parallel::StartPhoneticJapanese),
35			4 => Ok(Parallel::StartPhoneticChinese),
36			5 => Ok(Parallel::StopPhonetic),
37			_ => Err(nom::ErrorKind::Custom(9002)),
38		}
39	}
40}
41
42
43impl Into<u32> for Parallel {
44	#[inline]
45	fn into(self) -> u32 {
46		match self {
47			Parallel::End                   => 0,
48			Parallel::Start                 => 1,
49			Parallel::StartSupplementary    => 2,
50			Parallel::StartPhoneticJapanese => 3,
51			Parallel::StartPhoneticChinese  => 4,
52			Parallel::StopPhonetic          => 5,
53		}
54	}
55}