1use num_enum::{IntoPrimitive, TryFromPrimitive};
2
3#[derive(Debug, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]
4#[non_exhaustive]
5#[repr(u8)]
6pub enum Table1_2 {
7 Analysis = 0,
8 StartOfForecast,
9 VerifyingTimeOfForecast,
10 ObservationTime,
11 LocalTime,
12 SimulationStart,
13 Missing = 255,
14}
15
16#[derive(Debug, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]
17#[non_exhaustive]
18#[repr(u8)]
19pub enum Table4_4 {
20 Minute = 0,
21 Hour,
22 Day,
23 Month,
24 Year,
25 Decade,
26 Normal,
27 Century,
28 ThreeHours = 10,
29 SixHours,
30 TwelveHours,
31 Second,
32 Missing = 255,
33}
34
35impl Table4_4 {
36 pub fn short_expr(&self) -> Option<&'static str> {
37 match self {
38 Self::Minute => Some("m"),
39 Self::Hour => Some("h"),
40 Self::Day => Some("D"),
41 Self::Month => Some("M"),
42 Self::Year => Some("Y"),
43 Self::Decade => Some("10Y"),
44 Self::Normal => Some("30Y"),
45 Self::Century => Some("C"),
46 Self::ThreeHours => Some("3h"),
47 Self::SixHours => Some("6h"),
48 Self::TwelveHours => Some("12h"),
49 Self::Second => Some("s"),
50 Self::Missing => None,
51 }
52 }
53}
54
55#[derive(Debug, Clone, Eq, PartialEq, TryFromPrimitive, IntoPrimitive)]
56#[non_exhaustive]
57#[repr(u8)]
58pub enum Table5_6 {
59 FirstOrderSpatialDifferencing = 1,
60 SecondOrderSpatialDifferencing,
61 Missing = 255,
62}
63
64#[cfg(test)]
65mod tests {
66 use num_enum::TryFromPrimitiveError;
67
68 use super::*;
69 use crate::codetables::*;
70
71 #[test]
72 fn num_enum_conversion() {
73 assert_eq!((Table4_4::try_from(1u8)), Ok(Table4_4::Hour));
74 assert_eq!((Table4_4::try_from(10u8)), Ok(Table4_4::ThreeHours));
75 assert_eq!(
76 (Table4_4::try_from(254u8)),
77 Err(TryFromPrimitiveError { number: 254 })
78 );
79 }
80
81 #[test]
82 fn num_lookup_result_conversion() {
83 assert_eq!(Code::from(Table4_4::try_from(1u8)), Name(Table4_4::Hour));
84 assert_eq!(Code::from(Table4_4::try_from(254u8)), Num(254));
85 }
86}