Skip to content

Clean up imports, fix doc lints, get doctests to pass #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/density.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub const LBCF_KGCM_FACTOR: f64 = 0.062427973725314;
/// let mans_weight = Mass::from_stones(12.0);
/// let water_volume = mans_weight / body_density;
/// println!("{} gallons of water spilled on the floor", water_volume.as_gallons());
///}
/// }
/// ```
/// # Example2 - converting to ad-hoc units of density
///
Expand All @@ -40,9 +40,8 @@ pub const LBCF_KGCM_FACTOR: f64 = 0.062427973725314;
/// let density: Density = Mass::from_grams(3.0) / Volume:: from_litres(1.0);
/// let ounces = (density * Volume::from_quarts(1.0)).as_ounces();
/// println!("Answer is {} ounces per quart", ounces);
///}
/// }
/// ```

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, Default)]
pub struct Density {
Expand Down Expand Up @@ -74,7 +73,7 @@ impl Density {
}

// mass / volume = density
impl ::std::ops::Div<Volume> for Mass {
impl ::core::ops::Div<Volume> for Mass {
type Output = Density;

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

// mass / density = volume
impl ::std::ops::Div<Density> for Mass {
impl ::core::ops::Div<Density> for Mass {
type Output = Volume;

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

// volume * density = mass
impl ::std::ops::Mul<Density> for Volume {
impl ::core::ops::Mul<Density> for Volume {
type Output = Mass;

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

// density * volume = mass
impl ::std::ops::Mul<Volume> for Density {
impl ::core::ops::Mul<Volume> for Density {
type Output = Mass;

fn mul(self, other: Volume) -> Mass {
Expand Down
8 changes: 4 additions & 4 deletions src/humidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ impl Measurement for Humidity {
}
}

impl ::std::cmp::Eq for Humidity {}
impl ::std::cmp::PartialEq for Humidity {
impl ::core::cmp::Eq for Humidity {}
impl ::core::cmp::PartialEq for Humidity {
fn eq(&self, other: &Self) -> bool {
self.as_base_units() == other.as_base_units()
}
}

impl ::std::cmp::PartialOrd for Humidity {
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
impl ::core::cmp::PartialOrd for Humidity {
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
self.as_base_units().partial_cmp(&other.as_base_units())
}
}
Expand Down
47 changes: 21 additions & 26 deletions src/measurement.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/// The `Measurement` trait and the `implement_measurement!` macro
/// provides a common way for various measurements to be implemented.
//! The `Measurement` trait and the `implement_measurement!` macro
//! provides a common way for various measurements to be implemented.
///
/// All measurements implement this.
///
/// It provides conversion functions to and from raw numbers.
///
/// # Example
/// ```
/// #![no_std]
/// extern crate core;
/// // Importing the `implement_measurement` macro from the external crate is important
/// #[macro_use]
/// extern crate measurements;
///
/// use measurements::Measurement;
///
///
/// struct Cubits {
/// forearms: f64
/// }
Expand All @@ -35,16 +40,6 @@
/// // You should't need it in your own code.
/// fn main() { }
/// ```

#[cfg(feature = "no-std")]
use core as std;

#[cfg(feature = "no-std")]
use core::num::Float;

/// All measurements implement this.
///
/// It provides conversion functions to and from raw numbers.
pub trait Measurement {
/// Returns a string containing the most appropriate units for this quantity,
/// and a floating point value representing this quantity in those units.
Expand Down Expand Up @@ -84,13 +79,13 @@
}

/// This is a special macro that creates the code to implement
/// `std::fmt::Display`.
/// `core::fmt::Display`.
#[macro_export]
macro_rules! implement_display {
($($t:ty)*) => ($(

impl ::std::fmt::Display for $t {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
impl ::core::fmt::Display for $t {

Check failure on line 87 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {

Check failure on line 88 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`

Check failure on line 88 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
let (unit, value) = self.get_appropriate_units();
value.fmt(f)?; // Value
write!(f, "\u{00A0}{}", unit)
Expand All @@ -107,15 +102,15 @@

implement_display!( $t );

impl ::std::ops::Add for $t {
impl ::core::ops::Add for $t {

Check failure on line 105 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
type Output = Self;

fn add(self, rhs: Self) -> Self {
Self::from_base_units(self.as_base_units() + rhs.as_base_units())
}
}

impl ::std::ops::Sub for $t {
impl ::core::ops::Sub for $t {

Check failure on line 113 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
type Output = Self;

fn sub(self, rhs: Self) -> Self {
Expand All @@ -125,7 +120,7 @@

// Dividing a `$t` by another `$t` returns a ratio.
//
impl ::std::ops::Div<$t> for $t {
impl ::core::ops::Div<$t> for $t {

Check failure on line 123 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
type Output = f64;

fn div(self, rhs: Self) -> f64 {
Expand All @@ -135,7 +130,7 @@

// Dividing a `$t` by a factor returns a new portion of the measurement.
//
impl ::std::ops::Div<f64> for $t {
impl ::core::ops::Div<f64> for $t {

Check failure on line 133 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
type Output = Self;

fn div(self, rhs: f64) -> Self {
Expand All @@ -145,7 +140,7 @@

// Multiplying a `$t` by a factor increases (or decreases) that
// measurement a number of times.
impl ::std::ops::Mul<f64> for $t {
impl ::core::ops::Mul<f64> for $t {

Check failure on line 143 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
type Output = Self;

fn mul(self, rhs: f64) -> Self {
Expand All @@ -154,23 +149,23 @@
}

// Multiplying `$t` by a factor is commutative
impl ::std::ops::Mul<$t> for f64 {
impl ::core::ops::Mul<$t> for f64 {

Check failure on line 152 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
type Output = $t;

fn mul(self, rhs: $t) -> $t {
rhs * self
}
}

impl ::std::cmp::Eq for $t { }
impl ::std::cmp::PartialEq for $t {
impl ::core::cmp::Eq for $t { }

Check failure on line 160 in src/measurement.rs

View workflow job for this annotation

GitHub Actions / build-std (stable, std)

failed to resolve: you might be missing crate `core`
impl ::core::cmp::PartialEq for $t {
fn eq(&self, other: &Self) -> bool {
self.as_base_units() == other.as_base_units()
}
}

impl ::std::cmp::PartialOrd for $t {
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
impl ::core::cmp::PartialOrd for $t {
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
self.as_base_units().partial_cmp(&other.as_base_units())
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,47 +159,47 @@ impl Measurement for TemperatureDelta {
}
}

impl ::std::ops::Add<TemperatureDelta> for Temperature {
impl ::core::ops::Add<TemperatureDelta> for Temperature {
type Output = Temperature;

fn add(self, other: TemperatureDelta) -> Temperature {
Temperature::from_kelvin(self.degrees_kelvin + other.kelvin_degrees)
}
}

impl ::std::ops::Add<Temperature> for TemperatureDelta {
impl ::core::ops::Add<Temperature> for TemperatureDelta {
type Output = Temperature;

fn add(self, other: Temperature) -> Temperature {
other + self
}
}

impl ::std::ops::Sub<TemperatureDelta> for Temperature {
impl ::core::ops::Sub<TemperatureDelta> for Temperature {
type Output = Temperature;

fn sub(self, other: TemperatureDelta) -> Temperature {
Temperature::from_kelvin(self.degrees_kelvin - other.kelvin_degrees)
}
}

impl ::std::ops::Sub<Temperature> for Temperature {
impl ::core::ops::Sub<Temperature> for Temperature {
type Output = TemperatureDelta;

fn sub(self, other: Temperature) -> TemperatureDelta {
TemperatureDelta::from_kelvin(self.degrees_kelvin - other.degrees_kelvin)
}
}

impl ::std::cmp::Eq for Temperature {}
impl ::std::cmp::PartialEq for Temperature {
impl ::core::cmp::Eq for Temperature {}
impl ::core::cmp::PartialEq for Temperature {
fn eq(&self, other: &Self) -> bool {
self.as_base_units() == other.as_base_units()
}
}

impl ::std::cmp::PartialOrd for Temperature {
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
impl ::core::cmp::PartialOrd for Temperature {
fn partial_cmp(&self, other: &Self) -> Option<::core::cmp::Ordering> {
self.as_base_units().partial_cmp(&other.as_base_units())
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/torque_energy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub struct TorqueEnergy {
newton_metres: f64,
}

impl std::convert::From<TorqueEnergy> for Torque {
impl core::convert::From<TorqueEnergy> for Torque {
fn from(t: TorqueEnergy) -> Torque {
Torque::from_newton_metres(t.newton_metres)
}
}

impl std::convert::From<TorqueEnergy> for Energy {
impl core::convert::From<TorqueEnergy> for Energy {
fn from(t: TorqueEnergy) -> Energy {
Energy::from_joules(t.newton_metres)
}
Expand Down
Loading