grib/decoder/complex/
missing.rs

1use num::ToPrimitive;
2
3use self::DecodedValue::{Missing1, Missing2, Normal};
4
5#[derive(Debug, Clone, PartialEq)]
6pub(crate) enum DecodedValue<N: ToPrimitive> {
7    Normal(N),
8    Missing1,
9    Missing2,
10}
11
12impl<N: ToPrimitive> ToPrimitive for DecodedValue<N> {
13    fn to_i64(&self) -> Option<i64> {
14        match self {
15            Normal(v) => v.to_i64(),
16            Missing1 => None,
17            Missing2 => None,
18        }
19    }
20
21    fn to_u64(&self) -> Option<u64> {
22        match self {
23            Normal(v) => v.to_u64(),
24            Missing1 => None,
25            Missing2 => None,
26        }
27    }
28
29    fn to_f32(&self) -> Option<f32> {
30        match self {
31            Normal(v) => v.to_f32(),
32            Missing1 => Some(f32::NAN),
33            Missing2 => Some(f32::NAN),
34        }
35    }
36
37    fn to_f64(&self) -> Option<f64> {
38        match self {
39            Normal(v) => v.to_f64(),
40            Missing1 => Some(f64::NAN),
41            Missing2 => Some(f64::NAN),
42        }
43    }
44}