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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#![allow(dead_code)]
#![allow(non_camel_case_types)]

use std::fmt;
use std::cmp;
use std::ops;


macro_rules! allow_conversion {
    ($class:ident, $type:ident) => (
        impl From<$type> for $class {
            fn from(x: $type) -> Self {
                $class(x)
            }
        }
    )
}


macro_rules! overload_operators {
    ($class:ident, $type:ident) => (
        impl Eq for $class {}

        impl Ord for $class {
            fn cmp(&self, rhs: &Self) -> cmp::Ordering {
                if self.0 < rhs.0 {
                    cmp::Ordering::Less
                } else if self.0 > rhs.0 {
                    cmp::Ordering::Greater
                } else {
                    cmp::Ordering::Equal
                }
            }
        }

        impl ops::Add<$class> for $class {
            type Output = Self;

            fn add(self, rhs: Self) -> Self {
                $class::from(self.0 + rhs.0)
            }
        }

        impl ops::AddAssign<$class> for $class {
            fn add_assign(&mut self, rhs: Self) {
                self.0 += rhs.0
            }
        }

        impl ops::Sub<$class> for $class {
            type Output = Self;

            fn sub(self, rhs: Self) -> Self {
                $class::from(self.0 - rhs.0)
            }
        }

        impl ops::SubAssign<$class> for $class {
            fn sub_assign(&mut self, rhs: Self) {
                self.0 -= rhs.0
            }
        }

        impl ops::Mul<$type> for $class {
            type Output = Self;

            fn mul(self, rhs: $type) -> Self {
                $class::from(self.0 * rhs)
            }
        }

        impl ops::MulAssign<$type> for $class {
            fn mul_assign(&mut self, rhs: $type) {
                self.0 *= rhs
            }
        }

        impl ops::Div<$type> for $class {
            type Output = Self;

            fn div(self, rhs: $type) -> Self {
                $class::from(self.0 / rhs)
            }
        }

        impl ops::DivAssign<$type> for $class {
            fn div_assign(&mut self, rhs: $type) {
                self.0 /= rhs
            }
        }

        impl ops::Rem<$type> for $class {
            type Output = Self;

            fn rem(self, rhs: $type) -> Self {
                Self::from(self.0 % rhs)
            }
        }

        impl ops::RemAssign<$type> for $class {
            fn rem_assign(&mut self, rhs: $type) {
                self.0 %= rhs
            }
        }
    )
}


macro_rules! allow_display {
    ($class:ident) => (
        impl fmt::Display for $class {
            fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                self.0.fmt(formatter)
            }
        }
    )
}



/// should fit 1 to 18 [  ]
// pub type AtomGroup = u8;
pub type AtomGroup_type = u8;
#[derive(Debug, Clone, PartialEq, PartialOrd, Hash)]
pub struct AtomGroup(pub AtomGroup_type);
allow_conversion!(AtomGroup, AtomGroup_type);
overload_operators!(AtomGroup, AtomGroup_type);
allow_display!(AtomGroup);


/// should fit 0.0 to 294.0+, with normal precision [ gram / mol ]
// pub type AtomMass = f32;
pub type AtomMass_type = f32;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct AtomMass(pub AtomMass_type);
allow_conversion!(AtomMass, AtomMass_type);
overload_operators!(AtomMass, AtomMass_type);
allow_display!(AtomMass);


/// should fit 0 to 118+ [  ]
// pub type AtomNumber = u8;
pub type AtomNumber_type = u8;
#[derive(Debug, Clone, PartialEq, PartialOrd, Hash)]
pub struct AtomNumber(pub AtomNumber_type);
allow_conversion!(AtomNumber, AtomNumber_type);
overload_operators!(AtomNumber, AtomNumber_type);
allow_display!(AtomNumber);


/// should fit 0.0 to 1e5+, with high precision [ Joule ]
// pub type Energy = f64;
pub type Energy_type = f64;
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
pub struct Energy(pub Energy_type);
allow_conversion!(Energy, Energy_type);
overload_operators!(Energy, Energy_type);
allow_display!(Energy);


/// should fit -7 to 7 [  ]
// pub type AtomCharge = i8;
pub type AtomCharge_type = i8;
#[derive(Debug, Clone, PartialEq, PartialOrd, Hash)]
pub struct AtomCharge(pub AtomCharge_type);
allow_conversion!(AtomCharge, AtomCharge_type);
overload_operators!(AtomCharge, AtomCharge_type);
allow_display!(AtomCharge);


/// should fit 0.0 to 1e5+, with high precision [ gram ]
// pub type Mass = f64;
pub type Mass_type = f64;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct Mass(pub Mass_type);
allow_conversion!(Mass, Mass_type);
overload_operators!(Mass, Mass_type);
allow_display!(Mass);


/// should fit 0.0 to 1e5+, with high precision [ mol ]
// pub type Moles = f64;
pub type Moles_type = f64;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct Moles(pub Moles_type);
allow_conversion!(Moles, Moles_type);
overload_operators!(Moles, Moles_type);
allow_display!(Moles);


/// should fit -5.0 to 5.0, with normal precision [ volt ]
// pub type SEP = f32;
pub type SEP_type = f32;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct SEP(pub SEP_type);
allow_conversion!(SEP, SEP_type);
overload_operators!(SEP, SEP_type);
allow_display!(SEP);