1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Helicity types
use crate::types::Quantity;
use std::cmp::Ordering;

/// Marker trait for helicity.
pub trait Helicity: Quantity + PartialEq + PartialOrd {}

/// Marker trait for vertically integrated helicity.
pub trait IntHelicity: Quantity + PartialOrd + PartialEq {}

/// Helicity in m s<sup>-2</sup> units
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Serialize))]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Deserialize))]
pub struct HelicityMpS2(pub f64);

/// Vertically integrated helicity in m<sup>2</sup> s<sup>-2</sup> units
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Serialize))]
#[cfg_attr(feature = "use_serde", derive(serde_derive::Deserialize))]
pub struct IntHelicityM2pS2(pub f64);

impl Helicity for HelicityMpS2 {}
impl IntHelicity for IntHelicityM2pS2 {}

macro_rules! implQuantity {
    ($t:tt) => {
        impl Quantity for $t {
            #[inline]
            fn pack(val: f64) -> Self {
                $t(val)
            }

            #[inline]
            fn unpack(self) -> f64 {
                self.0
            }

            #[inline]
            fn unwrap(self) -> f64 {
                self.0
            }

            #[inline]
            fn into_option(self) -> Option<f64> {
                Some(self.0)
            }
        }

        implOpsForQuantity!($t);
    };
}

implQuantity!(HelicityMpS2);
implQuantity!(IntHelicityM2pS2);