77//! by an Area to get a Pressure.
88
99#![ deny( warnings, missing_docs) ]
10- #![ no_std]
1110
12- extern crate time;
11+ #![ cfg_attr( feature="no_std" , no_std) ]
12+
13+ #[ cfg( feature = "no_std" ) ]
14+ use core as std;
15+ #[ cfg( feature = "no_std" ) ]
16+ use core:: time as time;
17+
18+ #[ cfg( not( feature = "no_std" ) ) ]
19+ use std:: time as time;
20+
21+ use std:: f64:: consts:: PI as PI ;
1322
1423#[ macro_use]
1524mod measurement;
@@ -76,6 +85,8 @@ mod torque_energy;
7685pub use torque_energy:: TorqueEnergy ;
7786
7887pub mod prelude;
88+
89+ #[ cfg( test) ]
7990pub mod test_utils;
8091
8192/// For given types A, B and C, implement, using base units:
@@ -85,15 +96,15 @@ pub mod test_utils;
8596/// - C = A / B
8697macro_rules! impl_maths {
8798 ( $a: ty, $b: ty) => {
88- impl :: core :: ops:: Mul <$b> for $b {
99+ impl std :: ops:: Mul <$b> for $b {
89100 type Output = $a;
90101
91102 fn mul( self , rhs: $b) -> Self :: Output {
92103 Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
93104 }
94105 }
95106
96- impl :: core :: ops:: Div <$b> for $a {
107+ impl std :: ops:: Div <$b> for $a {
97108 type Output = $b;
98109
99110 fn div( self , rhs: $b) -> Self :: Output {
@@ -103,31 +114,31 @@ macro_rules! impl_maths {
103114 } ;
104115
105116 ( $a: ty, $b: ty, $c: ty) => {
106- impl :: core :: ops:: Mul <$b> for $c {
117+ impl std :: ops:: Mul <$b> for $c {
107118 type Output = $a;
108119
109120 fn mul( self , rhs: $b) -> Self :: Output {
110121 Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
111122 }
112123 }
113124
114- impl :: core :: ops:: Mul <$c> for $b {
125+ impl std :: ops:: Mul <$c> for $b {
115126 type Output = $a;
116127
117128 fn mul( self , rhs: $c) -> Self :: Output {
118129 Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
119130 }
120131 }
121132
122- impl :: core :: ops:: Div <$c> for $a {
133+ impl std :: ops:: Div <$c> for $a {
123134 type Output = $b;
124135
125136 fn div( self , rhs: $c) -> Self :: Output {
126137 Self :: Output :: from_base_units( self . as_base_units( ) / rhs. as_base_units( ) )
127138 }
128139 }
129140
130- impl :: core :: ops:: Div <$b> for $a {
141+ impl std :: ops:: Div <$b> for $a {
131142 type Output = $c;
132143
133144 fn div( self , rhs: $b) -> Self :: Output {
@@ -139,11 +150,13 @@ macro_rules! impl_maths {
139150
140151impl Measurement for time:: Duration {
141152 fn as_base_units ( & self ) -> f64 {
142- ( self . num_microseconds ( ) . unwrap ( ) as f64 ) / 1e6
153+ self . as_secs ( ) as f64 + ( f64 :: from ( self . subsec_nanos ( ) ) * 1e-9 )
143154 }
144155
145156 fn from_base_units ( units : f64 ) -> Self {
146- time:: Duration :: microseconds ( ( units * 1e6 ) as i64 )
157+ let subsec_nanos = ( ( units * 1e9 ) % 1e9 ) as u32 ;
158+ let secs = units as u64 ;
159+ time:: Duration :: new ( secs, subsec_nanos)
147160 }
148161
149162 fn get_base_units_name ( & self ) -> & ' static str {
@@ -171,34 +184,35 @@ impl_maths!(TorqueEnergy, Force, Length);
171184// Implement the divisions manually (the above macro only implemented the
172185// TorqueEnergy / X operations).
173186
174- impl :: core :: ops:: Div < Length > for Torque {
187+ impl std :: ops:: Div < Length > for Torque {
175188 type Output = Force ;
176189
177190 fn div ( self , rhs : Length ) -> Self :: Output {
178191 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
179192 }
180193}
181194
182- impl :: core :: ops:: Div < Force > for Torque {
195+ impl std :: ops:: Div < Force > for Torque {
183196 type Output = Length ;
184197
185198 fn div ( self , rhs : Force ) -> Self :: Output {
186199 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
187200 }
188201}
189202
190- impl :: core :: ops:: Div < Length > for Energy {
203+ impl std :: ops:: Div < Length > for Energy {
191204 type Output = Force ;
192205
193206 fn div ( self , rhs : Length ) -> Self :: Output {
194207 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
195208 }
196209}
197210
198- impl :: core :: ops:: Div < Force > for Energy {
211+ impl std :: ops:: Div < Force > for Energy {
199212 type Output = Length ;
200213
201214 fn div ( self , rhs : Force ) -> Self :: Output {
202215 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
203216 }
204217}
218+
0 commit comments