7
7
//! by an Area to get a Pressure.
8
8
9
9
#![ deny( warnings, missing_docs) ]
10
+ #![ no_std]
11
+
12
+ extern crate time;
10
13
11
14
#[ macro_use]
12
15
mod measurement;
@@ -73,15 +76,15 @@ pub mod test_utils;
73
76
/// - C = A / B
74
77
macro_rules! impl_maths {
75
78
( $a: ty, $b: ty) => {
76
- impl :: std :: ops:: Mul <$b> for $b {
79
+ impl :: core :: ops:: Mul <$b> for $b {
77
80
type Output = $a;
78
81
79
82
fn mul( self , rhs: $b) -> Self :: Output {
80
83
Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
81
84
}
82
85
}
83
86
84
- impl :: std :: ops:: Div <$b> for $a {
87
+ impl :: core :: ops:: Div <$b> for $a {
85
88
type Output = $b;
86
89
87
90
fn div( self , rhs: $b) -> Self :: Output {
@@ -91,31 +94,31 @@ macro_rules! impl_maths {
91
94
} ;
92
95
93
96
( $a: ty, $b: ty, $c: ty) => {
94
- impl :: std :: ops:: Mul <$b> for $c {
97
+ impl :: core :: ops:: Mul <$b> for $c {
95
98
type Output = $a;
96
99
97
100
fn mul( self , rhs: $b) -> Self :: Output {
98
101
Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
99
102
}
100
103
}
101
104
102
- impl :: std :: ops:: Mul <$c> for $b {
105
+ impl :: core :: ops:: Mul <$c> for $b {
103
106
type Output = $a;
104
107
105
108
fn mul( self , rhs: $c) -> Self :: Output {
106
109
Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
107
110
}
108
111
}
109
112
110
- impl :: std :: ops:: Div <$c> for $a {
113
+ impl :: core :: ops:: Div <$c> for $a {
111
114
type Output = $b;
112
115
113
116
fn div( self , rhs: $c) -> Self :: Output {
114
117
Self :: Output :: from_base_units( self . as_base_units( ) / rhs. as_base_units( ) )
115
118
}
116
119
}
117
120
118
- impl :: std :: ops:: Div <$b> for $a {
121
+ impl :: core :: ops:: Div <$b> for $a {
119
122
type Output = $c;
120
123
121
124
fn div( self , rhs: $b) -> Self :: Output {
@@ -125,15 +128,13 @@ macro_rules! impl_maths {
125
128
}
126
129
}
127
130
128
- impl Measurement for std :: time:: Duration {
131
+ impl Measurement for time:: Duration {
129
132
fn as_base_units ( & self ) -> f64 {
130
- self . as_secs ( ) as f64 + ( f64 :: from ( self . subsec_nanos ( ) ) * 1e-9 )
133
+ ( self . num_microseconds ( ) . unwrap ( ) as f64 ) / 1e6
131
134
}
132
135
133
136
fn from_base_units ( units : f64 ) -> Self {
134
- let subsec_nanos = ( ( units * 1e9 ) % 1e9 ) as u32 ;
135
- let secs = units as u64 ;
136
- std:: time:: Duration :: new ( secs, subsec_nanos)
137
+ time:: Duration :: microseconds ( ( units * 1e6 ) as i64 )
137
138
}
138
139
139
140
fn get_base_units_name ( & self ) -> & ' static str {
@@ -142,12 +143,12 @@ impl Measurement for std::time::Duration {
142
143
}
143
144
144
145
impl_maths ! ( Area , Length ) ;
145
- impl_maths ! ( Energy , std :: time:: Duration , Power ) ;
146
+ impl_maths ! ( Energy , time:: Duration , Power ) ;
146
147
impl_maths ! ( Force , Mass , Acceleration ) ;
147
148
impl_maths ! ( Force , Pressure , Area ) ;
148
- impl_maths ! ( Length , std :: time:: Duration , Speed ) ;
149
+ impl_maths ! ( Length , time:: Duration , Speed ) ;
149
150
impl_maths ! ( Power , Force , Speed ) ;
150
- impl_maths ! ( Speed , std :: time:: Duration , Acceleration ) ;
151
+ impl_maths ! ( Speed , time:: Duration , Acceleration ) ;
151
152
impl_maths ! ( Volume , Length , Area ) ;
152
153
impl_maths ! ( Power , AngularVelocity , Torque ) ;
153
154
@@ -159,31 +160,31 @@ impl_maths!(TorqueEnergy, Force, Length);
159
160
// Implement the divisions manually (the above macro only implemented the
160
161
// TorqueEnergy / X operations).
161
162
162
- impl :: std :: ops:: Div < Length > for Torque {
163
+ impl :: core :: ops:: Div < Length > for Torque {
163
164
type Output = Force ;
164
165
165
166
fn div ( self , rhs : Length ) -> Self :: Output {
166
167
Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
167
168
}
168
169
}
169
170
170
- impl :: std :: ops:: Div < Force > for Torque {
171
+ impl :: core :: ops:: Div < Force > for Torque {
171
172
type Output = Length ;
172
173
173
174
fn div ( self , rhs : Force ) -> Self :: Output {
174
175
Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
175
176
}
176
177
}
177
178
178
- impl :: std :: ops:: Div < Length > for Energy {
179
+ impl :: core :: ops:: Div < Length > for Energy {
179
180
type Output = Force ;
180
181
181
182
fn div ( self , rhs : Length ) -> Self :: Output {
182
183
Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
183
184
}
184
185
}
185
186
186
- impl :: std :: ops:: Div < Force > for Energy {
187
+ impl :: core :: ops:: Div < Force > for Energy {
187
188
type Output = Length ;
188
189
189
190
fn div ( self , rhs : Force ) -> Self :: Output {
0 commit comments