Skip to content

Commit

Permalink
Convert uom to 2018 edition.
Browse files Browse the repository at this point in the history
Generated code is still compatible with 2015 edition and the
`edition_check` test crate now verifies this.
  • Loading branch information
iliekturtles committed Sep 13, 2020
1 parent 6f51856 commit ddc5ea8
Show file tree
Hide file tree
Showing 65 changed files with 552 additions and 549 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "uom"
version = "0.29.0"
edition = "2018"
authors = ["Mike Boutin <[email protected]>"]
description = "Units of measurement"
documentation = "https://docs.rs/uom"
Expand Down
2 changes: 1 addition & 1 deletion examples/mks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[macro_use]
extern crate uom;

use length::{foot, meter};
use crate::length::{foot, meter};
use uom::fmt::DisplayStyle::Abbreviation;

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions examples/si.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Example showing how to use the pre-built SI system.
extern crate uom;

use uom::fmt::DisplayStyle::Abbreviation;
use uom::si::f32::*;
use uom::si::length::{centimeter, kilometer, meter};
Expand Down
54 changes: 27 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
)]

// Fail to compile if no underlying storage type features are specified.
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
#[cfg(not(any(
feature = "usize", feature = "u8", feature = "u16", feature = "u32", feature = "u64",
feature = "u128",
Expand Down Expand Up @@ -392,7 +392,7 @@ pub trait Conversion<V> {
/// no coefficient exists.
#[inline(always)]
fn coefficient() -> Self::T {
<Self::T as num::One>::one()
<Self::T as crate::num::One>::one()
}

/// Constant portion of [conversion factor](https://jcgm.bipm.org/vim/en/1.24.html) for
Expand All @@ -403,7 +403,7 @@ pub trait Conversion<V> {
#[inline(always)]
#[allow(unused_variables)]
fn constant(op: ConstantOp) -> Self::T {
<Self::T as num::Zero>::zero()
<Self::T as crate::num::Zero>::zero()
}

/// Instance [conversion factor](https://jcgm.bipm.org/vim/en/1.24.html).
Expand All @@ -429,8 +429,8 @@ pub trait ConversionFactor<V>:
+ lib::ops::Sub<Self, Output = Self>
+ lib::ops::Mul<Self, Output = Self>
+ lib::ops::Div<Self, Output = Self>
+ num::Zero
+ num::One
+ crate::num::Zero
+ crate::num::One
{
/// Raises a `ConversionFactor<V>` to an integer power.
fn powi(self, e: i32) -> Self;
Expand Down Expand Up @@ -462,14 +462,14 @@ pub trait Kind:
storage_types! {
types: Float;

impl ::Conversion<V> for V {
impl crate::Conversion<V> for V {
type T = V;

#[inline(always)]
fn constant(op: ::ConstantOp) -> Self::T {
fn constant(op: crate::ConstantOp) -> Self::T {
match op {
::ConstantOp::Add => -<Self::T as ::num::Zero>::zero(),
::ConstantOp::Sub => <Self::T as ::num::Zero>::zero(),
crate::ConstantOp::Add => -<Self::T as crate::num::Zero>::zero(),
crate::ConstantOp::Sub => <Self::T as crate::num::Zero>::zero(),
}
}

Expand All @@ -479,10 +479,10 @@ storage_types! {
}
}

impl ::ConversionFactor<V> for V {
impl crate::ConversionFactor<V> for V {
#[inline(always)]
fn powi(self, e: i32) -> Self {
<V as ::num::Float>::powi(self, e)
<V as crate::num::Float>::powi(self, e)
}

#[inline(always)]
Expand All @@ -495,16 +495,16 @@ storage_types! {
storage_types! {
types: PrimInt;

impl ::Conversion<V> for V {
type T = ::num::rational::Ratio<V>;
impl crate::Conversion<V> for V {
type T = crate::num::rational::Ratio<V>;

#[inline(always)]
fn into_conversion(&self) -> Self::T {
(*self).into()
}
}

impl ::ConversionFactor<V> for ::num::rational::Ratio<V> {
impl crate::ConversionFactor<V> for crate::num::rational::Ratio<V> {
#[inline(always)]
fn powi(self, e: i32) -> Self {
self.pow(e)
Expand All @@ -520,22 +520,22 @@ storage_types! {
storage_types! {
types: BigInt, BigUint;

impl ::Conversion<V> for V {
type T = ::num::rational::Ratio<V>;
impl crate::Conversion<V> for V {
type T = crate::num::rational::Ratio<V>;

#[inline(always)]
fn into_conversion(&self) -> Self::T {
self.clone().into()
}
}

impl ::ConversionFactor<V> for ::num::rational::Ratio<V> {
impl crate::ConversionFactor<V> for crate::num::rational::Ratio<V> {
#[inline(always)]
fn powi(self, e: i32) -> Self {
match e.cmp(&0) {
::lib::cmp::Ordering::Equal => <Self as ::num::One>::one(),
::lib::cmp::Ordering::Less => ::num::pow::pow(self.recip(), (-e) as usize),
::lib::cmp::Ordering::Greater => ::num::pow::pow(self, e as usize),
crate::lib::cmp::Ordering::Equal => <Self as crate::num::One>::one(),
crate::lib::cmp::Ordering::Less => crate::num::pow::pow(self.recip(), (-e) as usize),
crate::lib::cmp::Ordering::Greater => crate::num::pow::pow(self, e as usize),
}
}

Expand All @@ -549,7 +549,7 @@ storage_types! {
storage_types! {
types: Rational, Rational32, Rational64;

impl ::Conversion<V> for V {
impl crate::Conversion<V> for V {
type T = V;

#[inline(always)]
Expand All @@ -558,7 +558,7 @@ storage_types! {
}
}

impl ::ConversionFactor<V> for V {
impl crate::ConversionFactor<V> for V {
#[inline(always)]
fn powi(self, e: i32) -> Self {
self.pow(e)
Expand All @@ -574,7 +574,7 @@ storage_types! {
storage_types! {
types: BigRational;

impl ::Conversion<V> for V {
impl crate::Conversion<V> for V {
type T = V;

#[inline(always)]
Expand All @@ -583,13 +583,13 @@ storage_types! {
}
}

impl ::ConversionFactor<V> for V {
impl crate::ConversionFactor<V> for V {
#[inline(always)]
fn powi(self, e: i32) -> Self {
match e.cmp(&0) {
::lib::cmp::Ordering::Equal => <Self as ::num::One>::one(),
::lib::cmp::Ordering::Less => ::num::pow::pow(self.recip(), (-e) as usize),
::lib::cmp::Ordering::Greater => ::num::pow::pow(self, e as usize),
crate::lib::cmp::Ordering::Equal => <Self as crate::num::One>::one(),
crate::lib::cmp::Ordering::Less => crate::num::pow::pow(self.recip(), (-e) as usize),
crate::lib::cmp::Ordering::Greater => crate::num::pow::pow(self, e as usize),
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
/// # }
/// # }
/// # mod f32 {
/// # Q!(mks, f32/*, (centimeter, gram, second)*/);
/// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/);
/// # }
/// # }
/// ```
Expand Down Expand Up @@ -178,12 +178,14 @@ macro_rules! quantity {
type T = V;

#[inline(always)]
#[allow(clippy::inconsistent_digit_grouping)]
fn coefficient() -> Self::T {
quantity!(@coefficient $($conversion),+)
}

#[inline(always)]
#[allow(unused_variables)]
#[allow(clippy::inconsistent_digit_grouping)]
fn constant(op: $crate::ConstantOp) -> Self::T {
quantity!(@constant op $($conversion),+)
}
Expand Down Expand Up @@ -421,8 +423,8 @@ macro_rules! quantity {
{
super::fmt::Arguments {
dimension: $crate::lib::marker::PhantomData,
unit: unit,
style: style,
unit,
style,
}
}

Expand Down Expand Up @@ -462,8 +464,8 @@ macro_rules! quantity {
super::fmt::QuantityArguments {
arguments: super::fmt::Arguments {
dimension: $crate::lib::marker::PhantomData,
unit: unit,
style: style,
unit,
style,
},
quantity: self,
}
Expand All @@ -489,7 +491,7 @@ macro_rules! quantity {
{
super::fmt::QuantityArguments {
arguments: self,
quantity: quantity,
quantity,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/si/acceleration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ quantity! {
#[cfg(test)]
mod tests {
storage_types! {
use num::One;
use si::quantities::*;
use si::acceleration as a;
use si::length as l;
use si::time as t;
use tests::Test;
use crate::si::acceleration as a;
use crate::si::length as l;
use crate::si::quantities::*;
use crate::si::time as t;
use crate::tests::Test;
use crate::num::One;

#[test]
fn check_dimension() {
Expand Down
66 changes: 33 additions & 33 deletions src/si/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ quantity! {
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (::si::marker::AngleKind);
kind: dyn (crate::si::marker::AngleKind);
units {
/// SI derived unit of angle. It is the angle subtended at the center of a circle by an
/// arc that is equal in length to the radius of the circle.
Expand All @@ -30,45 +30,45 @@ quantity! {
}

#[cfg(feature = "f32")]
impl Angle<::si::SI<f32>, f32> {
impl Angle<crate::si::SI<f32>, f32> {
/// A half turn, i.e. an angle with a value of π as measured in radians
pub const HALF_TURN: Self = Self {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: ::lib::f32::consts::PI,
dimension: crate::lib::marker::PhantomData,
units: crate::lib::marker::PhantomData,
value: crate::lib::f32::consts::PI,
};

/// A full turn, i.e. an angle with a value of 2π as measured in radians
pub const FULL_TURN: Self = Self {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: 2. * ::lib::f32::consts::PI,
dimension: crate::lib::marker::PhantomData,
units: crate::lib::marker::PhantomData,
value: 2. * crate::lib::f32::consts::PI,
};
}

#[cfg(feature = "f64")]
impl Angle<::si::SI<f64>, f64> {
impl Angle<crate::si::SI<f64>, f64> {
/// A half turn, i.e. an angle with a value of π as measured in radians
pub const HALF_TURN: Self = Self {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: ::lib::f64::consts::PI,
dimension: crate::lib::marker::PhantomData,
units: crate::lib::marker::PhantomData,
value: crate::lib::f64::consts::PI,
};

/// A full turn, i.e. an angle with a value of 2π as measured in radians
pub const FULL_TURN: Self = Self {
dimension: ::lib::marker::PhantomData,
units: ::lib::marker::PhantomData,
value: 2. * ::lib::f64::consts::PI,
dimension: crate::lib::marker::PhantomData,
units: crate::lib::marker::PhantomData,
value: 2. * crate::lib::f64::consts::PI,
};
}

/// Implementation of various stdlib trigonometric functions
#[cfg(feature = "std")]
impl<U, V> Angle<U, V>
where
U: ::si::Units<V> + ?Sized,
V: ::num::Float + ::Conversion<V>,
U: crate::si::Units<V> + ?Sized,
V: crate::num::Float + crate::Conversion<V>,
{
/// Computes the value of the cosine of the angle.
#[inline(always)]
Expand Down Expand Up @@ -115,12 +115,12 @@ where
}

#[cfg(feature = "std")]
impl<D, U, V> ::si::Quantity<D, U, V>
impl<D, U, V> crate::si::Quantity<D, U, V>
where
D: ::si::Dimension + ?Sized,
U: ::si::Units<V> + ?Sized,
V: ::num::Float + ::Conversion<V>,
radian: ::Conversion<V, T = V::T>,
D: crate::si::Dimension + ?Sized,
U: crate::si::Units<V> + ?Sized,
V: crate::num::Float + crate::Conversion<V>,
radian: crate::Conversion<V, T = V::T>,
{
/// Computes the four quadrant arctangent of self (y) and other (x).
#[inline(always)]
Expand All @@ -132,11 +132,11 @@ where
#[cfg(test)]
mod tests {
storage_types! {
use ::lib::f64::consts::PI;
use num::{FromPrimitive, One};
use si::angle as a;
use si::quantities::*;
use tests::Test;
use crate::lib::f64::consts::PI;
use crate::num::{FromPrimitive, One};
use crate::si::angle as a;
use crate::si::quantities::*;
use crate::tests::Test;

#[test]
fn check_units() {
Expand All @@ -158,12 +158,12 @@ mod tests {
storage_types! {
types: Float;

use ::lib::f64::consts::PI;
use num::{FromPrimitive, Zero};
use si::angle as a;
use si::length as l;
use si::quantities::*;
use tests::Test;
use crate::lib::f64::consts::PI;
use crate::num::{FromPrimitive, Zero};
use crate::si::angle as a;
use crate::si::length as l;
use crate::si::quantities::*;
use crate::tests::Test;

#[test]
fn sanity() {
Expand Down
Loading

0 comments on commit ddc5ea8

Please sign in to comment.