diff --git a/src/lib.rs b/src/lib.rs index 2f9864b0..91dfebf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -431,8 +431,8 @@ pub trait Conversion { /// converting the given unit. To convert to the base unit for the quantity use `(value + /// constant()) * coefficient()`. To convert from the base unit, `(value / coefficient()) - /// constant()` is used. Implementation should return the additive identity (`Self::T::zero()`) - /// if no constant exists. See [ConstantOp](enum.ConstantOp.html) documentation for details - /// about parameter use to ensure the method optimizes correctly. + /// if no constant exists. See [`ConstantOp`] documentation for details about parameter use to + /// ensure the method optimizes correctly. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] #[allow(unused_variables)] @@ -515,8 +515,8 @@ pub trait Kind: storage_types! { types: Float; - impl crate::Conversion for V { - type T = V; + impl crate::Conversion for V { + type T = Self; #[inline(always)] fn constant(op: crate::ConstantOp) -> Self::T { @@ -532,14 +532,14 @@ storage_types! { } } - impl crate::ConversionFactor for V { + impl crate::ConversionFactor for V { #[inline(always)] fn powi(self, e: i32) -> Self { - ::powi(self, e) + ::powi(self, e) } #[inline(always)] - fn value(self) -> V { + fn value(self) -> Self { self } } @@ -738,7 +738,7 @@ pub mod str { impl Display for ParseQuantityError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - use ParseQuantityError::*; + use ParseQuantityError::{NoSeparator, UnknownUnit, ValueParseError}; match *self { NoSeparator => write!(f, "no space between quantity and units"), diff --git a/src/quantity.rs b/src/quantity.rs index 4e1bccb4..a58d332a 100644 --- a/src/quantity.rs +++ b/src/quantity.rs @@ -1,6 +1,6 @@ /// Macro to implement a [quantity][quantity] and associated [measurement units][measurement]. Note -/// that this macro must be executed in direct submodules of the module where the -/// [`system!`](macro.system.html) macro was executed. `@...` match arms are considered private. +/// that this macro must be executed in direct submodules of the module where the [`system!`] macro +/// was executed. `@...` match arms are considered private. /// /// * `$quantity_attr`: Quantity attributes. Generally used to set documentation comments for the /// quantity. @@ -13,7 +13,7 @@ /// represented as a `typenum` type-level integer (e.g. `N1`, `Z0`, `P1`, `P2`, ...). /// * `$kind`: [Kind][kind] of the quantity. Optional. This variable should only be specified when /// defining a quantity that has the same dimensions as another quantity but isn't comparable. -/// When not specified [`uom::Kind`](trait.Kind.html) is used. +/// When not specified [`crate::Kind`] is used. /// * `$unit`: Unit name (e.g. `meter`, `foot`). /// * `$conversion`: Conversion (coefficient and constant factor) from the unit to the base unit of /// the quantity (e.g. `3.048_E-1` to convert `foot` to `meter`. `1.0_E0, 273.15_E0` to convert @@ -125,7 +125,7 @@ macro_rules! quantity { pub trait Unit: __system::Unit {} /// Trait to identify [units][units] which have a [conversion factor][factor] for the - /// `Quantity`. See [`Conversion`](../../trait.Conversion.html). + /// `Quantity`. See [`crate::Conversion`]. /// /// ## Generic Parameters /// * `V`: Underlying storage type trait is implemented for. @@ -147,7 +147,7 @@ macro_rules! quantity { #[must_use = "method returns a static value"] #[allow(dead_code)] #[inline(always)] - pub fn description() -> &'static str { + pub const fn description() -> &'static str { $description } @@ -337,7 +337,7 @@ macro_rules! quantity { /// * `N`: Unit. #[must_use = "method returns a new object"] pub fn format_args( - unit: N, + _unit: N, style: $crate::fmt::DisplayStyle ) -> __system::fmt::Arguments where @@ -345,7 +345,7 @@ macro_rules! quantity { { __system::fmt::Arguments { dimension: $crate::lib::marker::PhantomData, - unit, + unit: $crate::lib::marker::PhantomData, style, } } @@ -378,7 +378,7 @@ macro_rules! quantity { #[must_use = "method returns a new object and does not mutate the original one"] pub fn into_format_args( self, - unit: N, + _unit: N, style: $crate::fmt::DisplayStyle ) -> __system::fmt::QuantityArguments where @@ -387,7 +387,7 @@ macro_rules! quantity { __system::fmt::QuantityArguments { arguments: __system::fmt::Arguments { dimension: $crate::lib::marker::PhantomData, - unit, + unit: $crate::lib::marker::PhantomData, style, }, quantity: self, diff --git a/src/si/electric_permittivity.rs b/src/si/electric_permittivity.rs index 69d0f9c5..c417c616 100644 --- a/src/si/electric_permittivity.rs +++ b/src/si/electric_permittivity.rs @@ -15,7 +15,7 @@ quantity! { Z0>; // luminous intensity units { @farad_per_meter: prefix!(none); "F/m", "farad per meter", "farads per meter"; - @vacuum_electric_permittivity: 8.854_187_8128_E-12; "ε₀", "vacuum electric permittivity", + @vacuum_electric_permittivity: 8.854_187_812_8_E-12; "ε₀", "vacuum electric permittivity", "vacuum electric permittivity"; } } diff --git a/src/si/magnetic_moment.rs b/src/si/magnetic_moment.rs index bb5b7102..dcc6362c 100644 --- a/src/si/magnetic_moment.rs +++ b/src/si/magnetic_moment.rs @@ -25,8 +25,8 @@ quantity! { "statA · cm²", "statampere square centimeter", "statampere square centimeters"; @erg_per_gauss: 1.0_E-7 / 1.0_E-4; "erg/G", "erg per gauss", "ergs per gauss"; - @bohr_magneton: 9.274_010_0783_E-24; "µ(Bohr)", "Bohr magneton", "Bohr magnetons"; - @nuclear_magneton: 5.050_783_7461_E-27; "μ(Nuclear)", "nuclear magneton", + @bohr_magneton: 9.274_010_078_3_E-24; "µ(Bohr)", "Bohr magneton", "Bohr magnetons"; + @nuclear_magneton: 5.050_783_746_1_E-27; "μ(Nuclear)", "nuclear magneton", "nuclear magnetons"; @atomic_unit_of_magnetic_dipole_moment: 1.854_802_015_66_E-23; "ħ · e/mₑ", "atomic unit of magnetic dipole moment", " atomic units of magnetic dipole moment"; diff --git a/src/si/mass_rate.rs b/src/si/mass_rate.rs index 55b1a600..8e440c19 100644 --- a/src/si/mass_rate.rs +++ b/src/si/mass_rate.rs @@ -100,7 +100,7 @@ quantity! { /// Ton per minute, metric. @ton_per_minute: 1.666_666_666_666_666_6_E1; "t/min", "ton per minute", "tons per minute"; /// Ton per hour, metric. - @ton_per_hour: 2.777777777777778_E-1; "t/h", "ton per hour", "tons per hour"; + @ton_per_hour: 2.777_777_777_777_778_E-1; "t/h", "ton per hour", "tons per hour"; /// Ton per day, metric. @ton_per_day: 1.157_407_407_407_407_4_E-2; "t/d", "ton per day", "tons per day"; } diff --git a/src/si/ratio.rs b/src/si/ratio.rs index bd789871..9ea65371 100644 --- a/src/si/ratio.rs +++ b/src/si/ratio.rs @@ -86,21 +86,21 @@ where /// Returns `e^(self)`, (the exponential function). #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn exp(self) -> Ratio { + pub fn exp(self) -> Self { Ratio::new::(self.value.exp()) } /// Returns 2^(self). #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn exp2(self) -> Ratio { + pub fn exp2(self) -> Self { Ratio::new::(self.value.exp2()) } /// Returns the natural logarithm of the number. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn ln(self) -> Ratio { + pub fn ln(self) -> Self { Ratio::new::(self.value.ln()) } @@ -111,28 +111,28 @@ where /// self.log10() can produce more accurate results for base 10. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn log(self, base: V) -> Ratio { + pub fn log(self, base: V) -> Self { Ratio::new::(self.value.log(base)) } /// Returns the base 2 logarithm of the number. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn log2(self) -> Ratio { + pub fn log2(self) -> Self { Ratio::new::(self.value.log2()) } /// Returns the base 10 logarithm of the number. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn log10(self) -> Ratio { + pub fn log10(self) -> Self { Ratio::new::(self.value.log10()) } /// Returns e^(self) - 1 in a way that is accurate even if the number is close to zero. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn exp_m1(self) -> Ratio { + pub fn exp_m1(self) -> Self { Ratio::new::(self.value.exp_m1()) } @@ -140,13 +140,13 @@ where /// operations were performed separately. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] - pub fn ln_1p(self) -> Ratio { + pub fn ln_1p(self) -> Self { Ratio::new::(self.value.ln_1p()) } } mod convert { - use super::*; + use super::Ratio; impl From for Ratio where @@ -163,14 +163,14 @@ mod convert { } storage_types! { - use super::*; + use super::Ratio; - impl From> for V + impl From> for V where - U: crate::si::Units + ?Sized, - V: crate::num::Num + crate::Conversion, + U: crate::si::Units + ?Sized, + Self: crate::num::Num + crate::Conversion, { - fn from(t: Ratio) -> Self { + fn from(t: Ratio) -> Self { t.value } } diff --git a/src/si/time.rs b/src/si/time.rs index 5f03de91..a5c8124f 100644 --- a/src/si/time.rs +++ b/src/si/time.rs @@ -96,7 +96,7 @@ where let nanos = (time % Time::::new::(V::one())).get::().to_u32(); match (secs, nanos) { - (Some(secs), Some(nanos)) => Ok(Duration::new(secs, nanos)), + (Some(secs), Some(nanos)) => Ok(Self::new(secs, nanos)), _ => Err(TryFromError::Overflow), } } diff --git a/src/system.rs b/src/system.rs index d73ff3c1..2a0e0c2a 100644 --- a/src/system.rs +++ b/src/system.rs @@ -1423,10 +1423,10 @@ macro_rules! system { pub struct Arguments where D: Dimension + ?Sized, - N: Unit, + N: Unit + ?Sized, { pub(super) dimension: $crate::lib::marker::PhantomData, - pub(super) unit: N, + pub(super) unit: $crate::lib::marker::PhantomData, pub(super) style: DisplayStyle, } @@ -1466,11 +1466,7 @@ macro_rules! system { N: Unit, { fn clone(&self) -> Self { - Self { - dimension: $crate::lib::marker::PhantomData, - unit: self.unit.clone(), - style: self.style.clone(), - } + *self } } diff --git a/src/unit.rs b/src/unit.rs index cf86fc7b..b6251243 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -283,8 +283,8 @@ macro_rules! unit { #[derive(Clone, Copy, Debug, Hash)] pub struct $unit; }; - (@coefficient $factor:expr, $const:expr) => { $factor }; - (@coefficient $factor:expr) => { $factor }; + (@coefficient $factor:expr, $const:expr) => { #[allow(clippy::eq_op)] {$factor} }; + (@coefficient $factor:expr) => { #[allow(clippy::eq_op)] {$factor} }; (@constant $op:ident $factor:expr, $const:expr) => { $const }; (@constant $op:ident $factor:expr) => { match $op {