File tree Expand file tree Collapse file tree 23 files changed +206
-206
lines changed Expand file tree Collapse file tree 23 files changed +206
-206
lines changed Original file line number Diff line number Diff line change @@ -69,17 +69,17 @@ impl Acceleration {
6969}
7070
7171impl Measurement for Acceleration {
72+ fn get_base_units_name ( & self ) -> & ' static str {
73+ "m/s\u{00B2} "
74+ }
75+
7276 fn as_base_units ( & self ) -> f64 {
7377 self . meters_per_second_per_second
7478 }
7579
7680 fn from_base_units ( units : f64 ) -> Self {
7781 Self :: from_meters_per_second_per_second ( units)
7882 }
79-
80- fn get_base_units_name ( & self ) -> & ' static str {
81- "m/s\u{00B2} "
82- }
8383}
8484
8585#[ cfg( feature = "from_str" ) ]
Original file line number Diff line number Diff line change @@ -90,17 +90,17 @@ impl Angle {
9090}
9191
9292impl Measurement for Angle {
93+ fn get_base_units_name ( & self ) -> & ' static str {
94+ "rad"
95+ }
96+
9397 fn as_base_units ( & self ) -> f64 {
9498 self . radians
9599 }
96100
97101 fn from_base_units ( units : f64 ) -> Self {
98102 Self :: from_radians ( units)
99103 }
100-
101- fn get_base_units_name ( & self ) -> & ' static str {
102- "rad"
103- }
104104}
105105
106106#[ cfg( feature = "from_str" ) ]
Original file line number Diff line number Diff line change @@ -58,17 +58,17 @@ impl AngularVelocity {
5858}
5959
6060impl Measurement for AngularVelocity {
61+ fn get_base_units_name ( & self ) -> & ' static str {
62+ "rad/s"
63+ }
64+
6165 fn as_base_units ( & self ) -> f64 {
6266 self . radians_per_second
6367 }
6468
6569 fn from_base_units ( units : f64 ) -> Self {
6670 Self :: from_radians_per_second ( units)
6771 }
68-
69- fn get_base_units_name ( & self ) -> & ' static str {
70- "rad/s"
71- }
7272}
7373
7474#[ cfg( feature = "from_str" ) ]
Original file line number Diff line number Diff line change @@ -277,18 +277,6 @@ impl Area {
277277}
278278
279279impl Measurement for Area {
280- fn as_base_units ( & self ) -> f64 {
281- self . square_meters
282- }
283-
284- fn from_base_units ( units : f64 ) -> Self {
285- Self :: from_square_meters ( units)
286- }
287-
288- fn get_base_units_name ( & self ) -> & ' static str {
289- "m\u{00B2} "
290- }
291-
292280 fn get_appropriate_units ( & self ) -> ( & ' static str , f64 ) {
293281 // Smallest to largest
294282 let list = [
@@ -303,6 +291,18 @@ impl Measurement for Area {
303291 ] ;
304292 self . pick_appropriate_units ( & list)
305293 }
294+
295+ fn get_base_units_name ( & self ) -> & ' static str {
296+ "m\u{00B2} "
297+ }
298+
299+ fn as_base_units ( & self ) -> f64 {
300+ self . square_meters
301+ }
302+
303+ fn from_base_units ( units : f64 ) -> Self {
304+ Self :: from_square_meters ( units)
305+ }
306306}
307307
308308#[ cfg( feature = "from_str" ) ]
Original file line number Diff line number Diff line change @@ -64,18 +64,6 @@ impl Current {
6464}
6565
6666impl Measurement for Current {
67- fn as_base_units ( & self ) -> f64 {
68- self . amperes
69- }
70-
71- fn from_base_units ( units : f64 ) -> Self {
72- Self :: from_amperes ( units)
73- }
74-
75- fn get_base_units_name ( & self ) -> & ' static str {
76- "A"
77- }
78-
7967 fn get_appropriate_units ( & self ) -> ( & ' static str , f64 ) {
8068 // Smallest to Largest
8169 let list = [
@@ -94,6 +82,18 @@ impl Measurement for Current {
9482 ] ;
9583 self . pick_appropriate_units ( & list)
9684 }
85+
86+ fn get_base_units_name ( & self ) -> & ' static str {
87+ "A"
88+ }
89+
90+ fn as_base_units ( & self ) -> f64 {
91+ self . amperes
92+ }
93+
94+ fn from_base_units ( units : f64 ) -> Self {
95+ Self :: from_amperes ( units)
96+ }
9797}
9898
9999implement_measurement ! { Current }
Original file line number Diff line number Diff line change @@ -139,18 +139,6 @@ impl Data {
139139}
140140
141141impl Measurement for Data {
142- fn as_base_units ( & self ) -> f64 {
143- self . octets
144- }
145-
146- fn from_base_units ( units : f64 ) -> Self {
147- Self :: from_octets ( units)
148- }
149-
150- fn get_base_units_name ( & self ) -> & ' static str {
151- "octets"
152- }
153-
154142 fn get_appropriate_units ( & self ) -> ( & ' static str , f64 ) {
155143 // Smallest to largest
156144 let list = [
@@ -164,6 +152,18 @@ impl Measurement for Data {
164152 ] ;
165153 self . pick_appropriate_units ( & list)
166154 }
155+
156+ fn get_base_units_name ( & self ) -> & ' static str {
157+ "octets"
158+ }
159+
160+ fn as_base_units ( & self ) -> f64 {
161+ self . octets
162+ }
163+
164+ fn from_base_units ( units : f64 ) -> Self {
165+ Self :: from_octets ( units)
166+ }
167167}
168168
169169implement_measurement ! { Data }
Original file line number Diff line number Diff line change @@ -110,17 +110,17 @@ impl ::std::ops::Mul<Volume> for Density {
110110}
111111
112112impl Measurement for Density {
113+ fn get_base_units_name ( & self ) -> & ' static str {
114+ "kg/m\u{00B3} "
115+ }
116+
113117 fn as_base_units ( & self ) -> f64 {
114118 self . kilograms_per_cubic_meter
115119 }
116120
117121 fn from_base_units ( units : f64 ) -> Self {
118122 Self :: from_kilograms_per_cubic_meter ( units)
119123 }
120-
121- fn get_base_units_name ( & self ) -> & ' static str {
122- "kg/m\u{00B3} "
123- }
124124}
125125
126126implement_measurement ! { Density }
Original file line number Diff line number Diff line change @@ -82,18 +82,6 @@ impl Energy {
8282}
8383
8484impl Measurement for Energy {
85- fn as_base_units ( & self ) -> f64 {
86- self . joules
87- }
88-
89- fn from_base_units ( units : f64 ) -> Self {
90- Self :: from_joules ( units)
91- }
92-
93- fn get_base_units_name ( & self ) -> & ' static str {
94- "J"
95- }
96-
9785 fn get_appropriate_units ( & self ) -> ( & ' static str , f64 ) {
9886 // Smallest to Largest
9987 let list = [
@@ -112,6 +100,18 @@ impl Measurement for Energy {
112100 ] ;
113101 self . pick_appropriate_units ( & list)
114102 }
103+
104+ fn get_base_units_name ( & self ) -> & ' static str {
105+ "J"
106+ }
107+
108+ fn as_base_units ( & self ) -> f64 {
109+ self . joules
110+ }
111+
112+ fn from_base_units ( units : f64 ) -> Self {
113+ Self :: from_joules ( units)
114+ }
115115}
116116
117117implement_measurement ! { Energy }
Original file line number Diff line number Diff line change @@ -107,18 +107,6 @@ impl Force {
107107}
108108
109109impl Measurement for Force {
110- fn as_base_units ( & self ) -> f64 {
111- self . newtons
112- }
113-
114- fn from_base_units ( units : f64 ) -> Self {
115- Self :: from_newtons ( units)
116- }
117-
118- fn get_base_units_name ( & self ) -> & ' static str {
119- "N"
120- }
121-
122110 fn get_appropriate_units ( & self ) -> ( & ' static str , f64 ) {
123111 // Smallest to largest
124112 let list = [
@@ -133,6 +121,18 @@ impl Measurement for Force {
133121 ] ;
134122 self . pick_appropriate_units ( & list)
135123 }
124+
125+ fn get_base_units_name ( & self ) -> & ' static str {
126+ "N"
127+ }
128+
129+ fn as_base_units ( & self ) -> f64 {
130+ self . newtons
131+ }
132+
133+ fn from_base_units ( units : f64 ) -> Self {
134+ Self :: from_newtons ( units)
135+ }
136136}
137137
138138implement_measurement ! { Force }
Original file line number Diff line number Diff line change @@ -131,18 +131,6 @@ impl Frequency {
131131}
132132
133133impl Measurement for Frequency {
134- fn as_base_units ( & self ) -> f64 {
135- self . hertz
136- }
137-
138- fn from_base_units ( units : f64 ) -> Self {
139- Self :: from_hertz ( units)
140- }
141-
142- fn get_base_units_name ( & self ) -> & ' static str {
143- "Hz"
144- }
145-
146134 fn get_appropriate_units ( & self ) -> ( & ' static str , f64 ) {
147135 // Smallest to largest
148136 let list = [
@@ -157,6 +145,18 @@ impl Measurement for Frequency {
157145 ] ;
158146 self . pick_appropriate_units ( & list)
159147 }
148+
149+ fn get_base_units_name ( & self ) -> & ' static str {
150+ "Hz"
151+ }
152+
153+ fn as_base_units ( & self ) -> f64 {
154+ self . hertz
155+ }
156+
157+ fn from_base_units ( units : f64 ) -> Self {
158+ Self :: from_hertz ( units)
159+ }
160160}
161161
162162implement_measurement ! { Frequency }
You can’t perform that action at this time.
0 commit comments