77//! by an Area to get a Pressure.
88
99#![ deny( warnings, missing_docs) ]
10+ #![ no_std]
11+
12+ extern crate time;
1013
1114#[ macro_use]
1215mod measurement;
@@ -73,15 +76,15 @@ pub mod test_utils;
7376/// - C = A / B
7477macro_rules! impl_maths {
7578 ( $a: ty, $b: ty) => {
76- impl :: std :: ops:: Mul <$b> for $b {
79+ impl :: core :: ops:: Mul <$b> for $b {
7780 type Output = $a;
7881
7982 fn mul( self , rhs: $b) -> Self :: Output {
8083 Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
8184 }
8285 }
8386
84- impl :: std :: ops:: Div <$b> for $a {
87+ impl :: core :: ops:: Div <$b> for $a {
8588 type Output = $b;
8689
8790 fn div( self , rhs: $b) -> Self :: Output {
@@ -91,31 +94,31 @@ macro_rules! impl_maths {
9194 } ;
9295
9396 ( $a: ty, $b: ty, $c: ty) => {
94- impl :: std :: ops:: Mul <$b> for $c {
97+ impl :: core :: ops:: Mul <$b> for $c {
9598 type Output = $a;
9699
97100 fn mul( self , rhs: $b) -> Self :: Output {
98101 Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
99102 }
100103 }
101104
102- impl :: std :: ops:: Mul <$c> for $b {
105+ impl :: core :: ops:: Mul <$c> for $b {
103106 type Output = $a;
104107
105108 fn mul( self , rhs: $c) -> Self :: Output {
106109 Self :: Output :: from_base_units( self . as_base_units( ) * rhs. as_base_units( ) )
107110 }
108111 }
109112
110- impl :: std :: ops:: Div <$c> for $a {
113+ impl :: core :: ops:: Div <$c> for $a {
111114 type Output = $b;
112115
113116 fn div( self , rhs: $c) -> Self :: Output {
114117 Self :: Output :: from_base_units( self . as_base_units( ) / rhs. as_base_units( ) )
115118 }
116119 }
117120
118- impl :: std :: ops:: Div <$b> for $a {
121+ impl :: core :: ops:: Div <$b> for $a {
119122 type Output = $c;
120123
121124 fn div( self , rhs: $b) -> Self :: Output {
@@ -125,15 +128,13 @@ macro_rules! impl_maths {
125128 }
126129}
127130
128- impl Measurement for std :: time:: Duration {
131+ impl Measurement for time:: Duration {
129132 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
131134 }
132135
133136 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 )
137138 }
138139
139140 fn get_base_units_name ( & self ) -> & ' static str {
@@ -142,12 +143,12 @@ impl Measurement for std::time::Duration {
142143}
143144
144145impl_maths ! ( Area , Length ) ;
145- impl_maths ! ( Energy , std :: time:: Duration , Power ) ;
146+ impl_maths ! ( Energy , time:: Duration , Power ) ;
146147impl_maths ! ( Force , Mass , Acceleration ) ;
147148impl_maths ! ( Force , Pressure , Area ) ;
148- impl_maths ! ( Length , std :: time:: Duration , Speed ) ;
149+ impl_maths ! ( Length , time:: Duration , Speed ) ;
149150impl_maths ! ( Power , Force , Speed ) ;
150- impl_maths ! ( Speed , std :: time:: Duration , Acceleration ) ;
151+ impl_maths ! ( Speed , time:: Duration , Acceleration ) ;
151152impl_maths ! ( Volume , Length , Area ) ;
152153impl_maths ! ( Power , AngularVelocity , Torque ) ;
153154
@@ -159,31 +160,31 @@ impl_maths!(TorqueEnergy, Force, Length);
159160// Implement the divisions manually (the above macro only implemented the
160161// TorqueEnergy / X operations).
161162
162- impl :: std :: ops:: Div < Length > for Torque {
163+ impl :: core :: ops:: Div < Length > for Torque {
163164 type Output = Force ;
164165
165166 fn div ( self , rhs : Length ) -> Self :: Output {
166167 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
167168 }
168169}
169170
170- impl :: std :: ops:: Div < Force > for Torque {
171+ impl :: core :: ops:: Div < Force > for Torque {
171172 type Output = Length ;
172173
173174 fn div ( self , rhs : Force ) -> Self :: Output {
174175 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
175176 }
176177}
177178
178- impl :: std :: ops:: Div < Length > for Energy {
179+ impl :: core :: ops:: Div < Length > for Energy {
179180 type Output = Force ;
180181
181182 fn div ( self , rhs : Length ) -> Self :: Output {
182183 Self :: Output :: from_base_units ( self . as_base_units ( ) / rhs. as_base_units ( ) )
183184 }
184185}
185186
186- impl :: std :: ops:: Div < Force > for Energy {
187+ impl :: core :: ops:: Div < Force > for Energy {
187188 type Output = Length ;
188189
189190 fn div ( self , rhs : Force ) -> Self :: Output {
0 commit comments