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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keywords = ["measurements", "lengths", "weights", "temperatures", "volumes"]
description = "Handle metric, imperial, and other measurements with ease! Types: Length, Temperature, Weight, Volume, Pressure"
license = "MIT"
readme = "README.md"
edition = "2018"

[features]
std = []
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ measurements = "0.11"
In your code...

```rust
extern crate measurements;

use measurements::{Length, Pressure, Temperature, Volume, Mass};

fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/engine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate measurements;
use measurements::{AngularVelocity, Power};

fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/format_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate measurements;
use measurements::*;

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions examples/frequency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate measurements;

fn main() {
// Sinusiodal Oscilator moves at 5 Hz across 50 mm
let f = measurements::Frequency::from_hertz(5.0);
Expand Down
10 changes: 3 additions & 7 deletions src/acceleration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Types and constants for handling acceleration.

use super::length;
use super::measurement::*;
use crate::{length, measurement::*};
#[cfg(feature = "from_str")]
use regex::Regex;
#[cfg(feature = "from_str")]
Expand All @@ -13,7 +12,6 @@ use std::str::FromStr;
/// # Example
///
/// ```
/// extern crate measurements;
/// use measurements::{Acceleration, Length, Speed};
/// use std::time::Duration;
///
Expand Down Expand Up @@ -120,15 +118,13 @@ implement_measurement! { Acceleration }
#[cfg(test)]
mod test {

use super::*;
use speed::Speed;
use test_utils::assert_almost_eq;
use crate::{speed::Speed, test_utils::assert_almost_eq, *};

// Metric
#[test]
fn speed_over_time() {
let s1 = Speed::from_meters_per_second(10.0);
let t1 = ::time::Duration::new(5, 0);
let t1 = crate::time::Duration::new(5, 0);
let i1 = s1 / t1;
let r1 = i1.as_meters_per_second_per_second();
assert_almost_eq(r1, 2.0);
Expand Down
8 changes: 3 additions & 5 deletions src/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Angle {
impl Angle {
/// Create a new Angle from a floating point value in degrees
pub fn from_degrees(degrees: f64) -> Self {
Angle::from_radians(degrees * ::PI / 180.0)
Angle::from_radians(degrees * crate::PI / 180.0)
}

/// Create a new Angle from a floating point value in radians
Expand All @@ -38,7 +38,7 @@ impl Angle {

/// Convert this Angle to a floating point value in degrees
pub fn as_degrees(&self) -> f64 {
self.radians * 180.0 / ::PI
self.radians * 180.0 / crate::PI
}

/// Convert this Angle to a floating point value in radians
Expand Down Expand Up @@ -134,9 +134,7 @@ implement_measurement! { Angle }

#[cfg(test)]
mod test {
use angle::*;
use std::f64::consts::PI;
use test_utils::assert_almost_eq;
use crate::{angle::*, test_utils::assert_almost_eq, PI};

#[test]
fn radians() {
Expand Down
4 changes: 2 additions & 2 deletions src/angular_velocity.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Types and constants for handling speed of rotation (angular velocity)

use super::measurement::*;
use crate::PI;
#[cfg(feature = "from_str")]
use regex::Regex;
#[cfg(feature = "from_str")]
use std::str::FromStr;
use PI;

/// The 'AngularVelocity' struct can be used to deal with angular velocities in a common way.
///
Expand Down Expand Up @@ -106,7 +106,7 @@ implement_measurement! { AngularVelocity }
#[cfg(test)]
mod test {
use super::*;
use test_utils::assert_almost_eq;
use crate::test_utils::assert_almost_eq;

#[test]
fn rpm() {
Expand Down
3 changes: 1 addition & 2 deletions src/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ implement_measurement! { Area }

#[cfg(test)]
mod test {
use area::*;
use test_utils::assert_almost_eq;
use crate::{area::*, test_utils::assert_almost_eq};

#[test]
fn square_meters() {
Expand Down
3 changes: 1 addition & 2 deletions src/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ implement_measurement! { Current }

#[cfg(test)]
mod test {
use current::*;
use test_utils::assert_almost_eq;
use crate::{current::*, test_utils::assert_almost_eq};

#[test]
pub fn as_amperes() {
Expand Down
3 changes: 1 addition & 2 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ implement_measurement! { Data }

#[cfg(test)]
mod test {
use data::*;
use test_utils::assert_almost_eq;
use crate::{data::*, test_utils::assert_almost_eq};

// Metric
#[test]
Expand Down
46 changes: 19 additions & 27 deletions src/density.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Types and constants for handling density.

use super::measurement::*;
use mass::Mass;
use volume::Volume;
use crate::{mass::Mass, volume::Volume};

// Constants, metric
/// Number of pound per cubic foot in 1 kilograms per cubic meter
Expand All @@ -14,35 +13,28 @@ pub const LBCF_KGCM_FACTOR: f64 = 0.062427973725314;
/// # Example1 - calculating volume from units of mass and density
///
/// ```
/// extern crate measurements;
/// use measurements::{Density, Mass, Volume};
///
/// fn main() {
/// // Q: A 12 stone man hops into a brimming full bath, completely emersing himself.
/// // How many gallons of water spill on the floor?
/// // (Assume The human body is roughly about as dense as water - 1 gm/cm³)
/// //
/// let body_density: Density = Mass::from_grams(1.0) / Volume:: from_cubic_centimetres(1.0);
/// 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());
///}
/// // Q: A 12 stone man hops into a brimming full bath, completely emersing himself.
/// // How many gallons of water spill on the floor?
/// // (Assume The human body is roughly about as dense as water - 1 gm/cm³)
/// //
/// let body_density: Density = Mass::from_grams(1.0) / Volume:: from_cubic_centimetres(1.0);
/// 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
///
/// ```
/// extern crate measurements;
/// use measurements::{Density, Mass, Volume};
///
/// fn main() {
/// // Q: what is 3 grams per litre in units of ounces per quart?
/// //
/// 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);
///}
/// // Q: what is 3 grams per litre in units of ounces per quart?
/// //
/// 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 +66,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 +75,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 +84,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 +93,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 Expand Up @@ -129,7 +121,7 @@ implement_measurement! { Density }
mod test {

use super::*;
use test_utils::assert_almost_eq;
use crate::test_utils::assert_almost_eq;

// Metric
#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/energy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ implement_measurement! { Energy }

#[cfg(test)]
mod test {
use energy::*;
use test_utils::assert_almost_eq;
use crate::{energy::*, test_utils::assert_almost_eq};

#[test]
pub fn as_kcalories() {
Expand Down
3 changes: 1 addition & 2 deletions src/force.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ implement_measurement! { Force }

#[cfg(test)]
mod test {
use force::*;
use test_utils::assert_almost_eq;
use crate::{force::*, test_utils::assert_almost_eq};

#[test]
pub fn newtons() {
Expand Down
5 changes: 2 additions & 3 deletions src/frequency.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Types and constants for handling frequencies.

use super::measurement::*;
use time;
use crate::time;

/// Number of nanohertz in a Hz
pub const HERTZ_NANOHERTZ_FACTOR: f64 = 1e9;
Expand Down Expand Up @@ -164,8 +164,7 @@ implement_measurement! { Frequency }
#[cfg(test)]
mod test {
use super::*;
use test_utils::assert_almost_eq;
use time;
use crate::{test_utils::assert_almost_eq, time};

#[test]
pub fn hertz() {
Expand Down
15 changes: 6 additions & 9 deletions src/humidity.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Types and constants for handling humidity.

use super::measurement::*;
use density::Density;
use pressure::Pressure;
use temperature::Temperature;
use crate::{density::Density, pressure::Pressure, temperature::Temperature};

/// The `Humidity` struct can be used to deal with relative humidity
/// in air in a common way. Relative humidity is an important metric used
Expand Down Expand Up @@ -163,15 +161,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 All @@ -180,8 +178,7 @@ implement_display!(Humidity);

#[cfg(test)]
mod test {
use humidity::*;
use test_utils::assert_almost_eq;
use crate::{humidity::*, test_utils::assert_almost_eq};

// Humidity Units
#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ implement_measurement! { Length }

#[cfg(test)]
mod test {
use length::*;
use test_utils::assert_almost_eq;
use crate::{length::*, test_utils::assert_almost_eq};

// Metric
#[test]
Expand Down
Loading