msime_engine/vietnamese/
mod.rs1pub mod scheme;
4
5pub use scheme::VietnameseScheme;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
9#[repr(u8)]
10pub enum InputMethod {
11 #[default]
13 Telex = 0,
14 Vni = 1,
16}
17
18impl InputMethod {
19 pub fn from_u8(value: u8) -> Option<Self> {
20 Some(match value {
21 0 => Self::Telex,
22 1 => Self::Vni,
23 _ => return None,
24 })
25 }
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
30#[repr(u8)]
31pub enum ToneStyle {
32 #[default]
34 Modern = 0,
35 Classic = 1,
37}
38
39impl ToneStyle {
40 pub fn from_u8(value: u8) -> Option<Self> {
41 Some(match value {
42 0 => Self::Modern,
43 1 => Self::Classic,
44 _ => return None,
45 })
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn ordinals_round_trip_and_out_of_range_values_are_refused() {
55 for method in [InputMethod::Telex, InputMethod::Vni] {
56 assert_eq!(InputMethod::from_u8(method as u8), Some(method));
57 }
58 for style in [ToneStyle::Modern, ToneStyle::Classic] {
59 assert_eq!(ToneStyle::from_u8(style as u8), Some(style));
60 }
61 assert_eq!(InputMethod::from_u8(2), None);
62 assert_eq!(ToneStyle::from_u8(2), None);
63 assert_eq!(InputMethod::default(), InputMethod::Telex);
64 assert_eq!(ToneStyle::default(), ToneStyle::Modern);
65 }
66}