Skip to content

Commit 66646d4

Browse files
committed
replace use of std with core where required
1 parent 18286e1 commit 66646d4

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

src/density.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Density {
7373
}
7474

7575
// mass / volume = density
76-
impl ::std::ops::Div<Volume> for Mass {
76+
impl ::core::ops::Div<Volume> for Mass {
7777
type Output = Density;
7878

7979
fn div(self, other: Volume) -> Density {
@@ -82,7 +82,7 @@ impl ::std::ops::Div<Volume> for Mass {
8282
}
8383

8484
// mass / density = volume
85-
impl ::std::ops::Div<Density> for Mass {
85+
impl ::core::ops::Div<Density> for Mass {
8686
type Output = Volume;
8787

8888
fn div(self, other: Density) -> Volume {
@@ -91,7 +91,7 @@ impl ::std::ops::Div<Density> for Mass {
9191
}
9292

9393
// volume * density = mass
94-
impl ::std::ops::Mul<Density> for Volume {
94+
impl ::core::ops::Mul<Density> for Volume {
9595
type Output = Mass;
9696

9797
fn mul(self, other: Density) -> Mass {
@@ -100,7 +100,7 @@ impl ::std::ops::Mul<Density> for Volume {
100100
}
101101

102102
// density * volume = mass
103-
impl ::std::ops::Mul<Volume> for Density {
103+
impl ::core::ops::Mul<Volume> for Density {
104104
type Output = Mass;
105105

106106
fn mul(self, other: Volume) -> Mass {

src/humidity.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ impl Measurement for Humidity {
163163
}
164164
}
165165

166-
impl ::std::cmp::Eq for Humidity {}
167-
impl ::std::cmp::PartialEq for Humidity {
166+
impl ::core::cmp::Eq for Humidity {}
167+
impl ::core::cmp::PartialEq for Humidity {
168168
fn eq(&self, other: &Self) -> bool {
169169
self.as_base_units() == other.as_base_units()
170170
}
171171
}
172172

173-
impl ::std::cmp::PartialOrd for Humidity {
174-
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
173+
impl ::core::cmp::PartialOrd for Humidity {
174+
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
175175
self.as_base_units().partial_cmp(&other.as_base_units())
176176
}
177177
}

src/measurement.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
///
88
/// # Example
99
/// ```
10+
/// extern crate core;
1011
/// // Importing the `implement_measurement` macro from the external crate is important
1112
/// #[macro_use]
1213
/// extern crate measurements;
1314
///
1415
/// use measurements::Measurement;
1516
///
17+
///
1618
/// struct Cubits {
1719
/// forearms: f64
1820
/// }
@@ -38,9 +40,6 @@
3840
/// // You should't need it in your own code.
3941
/// fn main() { }
4042
/// ```
41-
///
42-
/// *Note*: If you are in a `no_std` environment, you have to
43-
/// `use core as std;` for the macros to run.
4443
pub trait Measurement {
4544
/// Returns a string containing the most appropriate units for this quantity,
4645
/// and a floating point value representing this quantity in those units.
@@ -80,13 +79,13 @@ pub trait Measurement {
8079
}
8180

8281
/// This is a special macro that creates the code to implement
83-
/// `std::fmt::Display`.
82+
/// `core::fmt::Display`.
8483
#[macro_export]
8584
macro_rules! implement_display {
8685
($($t:ty)*) => ($(
8786

88-
impl ::std::fmt::Display for $t {
89-
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
87+
impl ::core::fmt::Display for $t {
88+
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9089
let (unit, value) = self.get_appropriate_units();
9190
value.fmt(f)?; // Value
9291
write!(f, "\u{00A0}{}", unit)
@@ -103,15 +102,15 @@ macro_rules! implement_measurement {
103102

104103
implement_display!( $t );
105104

106-
impl ::std::ops::Add for $t {
105+
impl ::core::ops::Add for $t {
107106
type Output = Self;
108107

109108
fn add(self, rhs: Self) -> Self {
110109
Self::from_base_units(self.as_base_units() + rhs.as_base_units())
111110
}
112111
}
113112

114-
impl ::std::ops::Sub for $t {
113+
impl ::core::ops::Sub for $t {
115114
type Output = Self;
116115

117116
fn sub(self, rhs: Self) -> Self {
@@ -121,7 +120,7 @@ macro_rules! implement_measurement {
121120

122121
// Dividing a `$t` by another `$t` returns a ratio.
123122
//
124-
impl ::std::ops::Div<$t> for $t {
123+
impl ::core::ops::Div<$t> for $t {
125124
type Output = f64;
126125

127126
fn div(self, rhs: Self) -> f64 {
@@ -131,7 +130,7 @@ macro_rules! implement_measurement {
131130

132131
// Dividing a `$t` by a factor returns a new portion of the measurement.
133132
//
134-
impl ::std::ops::Div<f64> for $t {
133+
impl ::core::ops::Div<f64> for $t {
135134
type Output = Self;
136135

137136
fn div(self, rhs: f64) -> Self {
@@ -141,7 +140,7 @@ macro_rules! implement_measurement {
141140

142141
// Multiplying a `$t` by a factor increases (or decreases) that
143142
// measurement a number of times.
144-
impl ::std::ops::Mul<f64> for $t {
143+
impl ::core::ops::Mul<f64> for $t {
145144
type Output = Self;
146145

147146
fn mul(self, rhs: f64) -> Self {
@@ -150,23 +149,23 @@ macro_rules! implement_measurement {
150149
}
151150

152151
// Multiplying `$t` by a factor is commutative
153-
impl ::std::ops::Mul<$t> for f64 {
152+
impl ::core::ops::Mul<$t> for f64 {
154153
type Output = $t;
155154

156155
fn mul(self, rhs: $t) -> $t {
157156
rhs * self
158157
}
159158
}
160159

161-
impl ::std::cmp::Eq for $t { }
162-
impl ::std::cmp::PartialEq for $t {
160+
impl ::core::cmp::Eq for $t { }
161+
impl ::core::cmp::PartialEq for $t {
163162
fn eq(&self, other: &Self) -> bool {
164163
self.as_base_units() == other.as_base_units()
165164
}
166165
}
167166

168-
impl ::std::cmp::PartialOrd for $t {
169-
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
167+
impl ::core::cmp::PartialOrd for $t {
168+
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
170169
self.as_base_units().partial_cmp(&other.as_base_units())
171170
}
172171
}

src/temperature.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,47 +159,47 @@ impl Measurement for TemperatureDelta {
159159
}
160160
}
161161

162-
impl ::std::ops::Add<TemperatureDelta> for Temperature {
162+
impl ::core::ops::Add<TemperatureDelta> for Temperature {
163163
type Output = Temperature;
164164

165165
fn add(self, other: TemperatureDelta) -> Temperature {
166166
Temperature::from_kelvin(self.degrees_kelvin + other.kelvin_degrees)
167167
}
168168
}
169169

170-
impl ::std::ops::Add<Temperature> for TemperatureDelta {
170+
impl ::core::ops::Add<Temperature> for TemperatureDelta {
171171
type Output = Temperature;
172172

173173
fn add(self, other: Temperature) -> Temperature {
174174
other + self
175175
}
176176
}
177177

178-
impl ::std::ops::Sub<TemperatureDelta> for Temperature {
178+
impl ::core::ops::Sub<TemperatureDelta> for Temperature {
179179
type Output = Temperature;
180180

181181
fn sub(self, other: TemperatureDelta) -> Temperature {
182182
Temperature::from_kelvin(self.degrees_kelvin - other.kelvin_degrees)
183183
}
184184
}
185185

186-
impl ::std::ops::Sub<Temperature> for Temperature {
186+
impl ::core::ops::Sub<Temperature> for Temperature {
187187
type Output = TemperatureDelta;
188188

189189
fn sub(self, other: Temperature) -> TemperatureDelta {
190190
TemperatureDelta::from_kelvin(self.degrees_kelvin - other.degrees_kelvin)
191191
}
192192
}
193193

194-
impl ::std::cmp::Eq for Temperature {}
195-
impl ::std::cmp::PartialEq for Temperature {
194+
impl ::core::cmp::Eq for Temperature {}
195+
impl ::core::cmp::PartialEq for Temperature {
196196
fn eq(&self, other: &Self) -> bool {
197197
self.as_base_units() == other.as_base_units()
198198
}
199199
}
200200

201-
impl ::std::cmp::PartialOrd for Temperature {
202-
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
201+
impl ::core::cmp::PartialOrd for Temperature {
202+
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
203203
self.as_base_units().partial_cmp(&other.as_base_units())
204204
}
205205
}

src/torque_energy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pub struct TorqueEnergy {
1212
newton_metres: f64,
1313
}
1414

15-
impl std::convert::From<TorqueEnergy> for Torque {
15+
impl core::convert::From<TorqueEnergy> for Torque {
1616
fn from(t: TorqueEnergy) -> Torque {
1717
Torque::from_newton_metres(t.newton_metres)
1818
}
1919
}
2020

21-
impl std::convert::From<TorqueEnergy> for Energy {
21+
impl core::convert::From<TorqueEnergy> for Energy {
2222
fn from(t: TorqueEnergy) -> Energy {
2323
Energy::from_joules(t.newton_metres)
2424
}

0 commit comments

Comments
 (0)