Skip to content

Commit

Permalink
Merge pull request #443 from hellow554/master
Browse files Browse the repository at this point in the history
Fix some clippy lints
  • Loading branch information
iliekturtles authored Jan 27, 2024
2 parents 56fe329 + 35e0cfa commit 9abc39e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ pub trait Conversion<V> {
/// 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)]
Expand Down Expand Up @@ -515,8 +515,8 @@ pub trait Kind:
storage_types! {
types: Float;

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

#[inline(always)]
fn constant(op: crate::ConstantOp) -> Self::T {
Expand All @@ -532,14 +532,14 @@ storage_types! {
}
}

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

#[inline(always)]
fn value(self) -> V {
fn value(self) -> Self {
self
}
}
Expand Down Expand Up @@ -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"),
Expand Down
18 changes: 9 additions & 9 deletions src/quantity.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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<V>`](../../trait.Conversion.html).
/// `Quantity`. See [`crate::Conversion<V>`].
///
/// ## Generic Parameters
/// * `V`: Underlying storage type trait is implemented for.
Expand All @@ -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
}

Expand Down Expand Up @@ -337,15 +337,15 @@ macro_rules! quantity {
/// * `N`: Unit.
#[must_use = "method returns a new object"]
pub fn format_args<N>(
unit: N,
_unit: N,
style: $crate::fmt::DisplayStyle
) -> __system::fmt::Arguments<Dimension, N>
where
N: Unit
{
__system::fmt::Arguments {
dimension: $crate::lib::marker::PhantomData,
unit,
unit: $crate::lib::marker::PhantomData,
style,
}
}
Expand Down Expand Up @@ -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<N>(
self,
unit: N,
_unit: N,
style: $crate::fmt::DisplayStyle
) -> __system::fmt::QuantityArguments<Dimension, U, V, N>
where
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/si/electric_permittivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/si/magnetic_moment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/si/mass_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
28 changes: 14 additions & 14 deletions src/si/ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<U, V> {
pub fn exp(self) -> Self {
Ratio::new::<ratio>(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<U, V> {
pub fn exp2(self) -> Self {
Ratio::new::<ratio>(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<U, V> {
pub fn ln(self) -> Self {
Ratio::new::<ratio>(self.value.ln())
}

Expand All @@ -111,42 +111,42 @@ 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<U, V> {
pub fn log(self, base: V) -> Self {
Ratio::new::<ratio>(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<U, V> {
pub fn log2(self) -> Self {
Ratio::new::<ratio>(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<U, V> {
pub fn log10(self) -> Self {
Ratio::new::<ratio>(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<U, V> {
pub fn exp_m1(self) -> Self {
Ratio::new::<ratio>(self.value.exp_m1())
}

/// Returns ln(1+n) (natural logarithm) more accurately than if the
/// 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<U, V> {
pub fn ln_1p(self) -> Self {
Ratio::new::<ratio>(self.value.ln_1p())
}
}

mod convert {
use super::*;
use super::Ratio;

impl<U, V> From<V> for Ratio<U, V>
where
Expand All @@ -163,14 +163,14 @@ mod convert {
}

storage_types! {
use super::*;
use super::Ratio;

impl<U> From<Ratio<U, V>> for V
impl<U> From<Ratio<U, Self>> for V
where
U: crate::si::Units<V> + ?Sized,
V: crate::num::Num + crate::Conversion<V>,
U: crate::si::Units<Self> + ?Sized,
Self: crate::num::Num + crate::Conversion<Self>,
{
fn from(t: Ratio<U, V>) -> Self {
fn from(t: Ratio<U, Self>) -> Self {
t.value
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/si/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ where
let nanos = (time % Time::<U, V>::new::<second>(V::one())).get::<nanosecond>().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),
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,10 +1423,10 @@ macro_rules! system {
pub struct Arguments<D, N>
where
D: Dimension + ?Sized,
N: Unit,
N: Unit + ?Sized,
{
pub(super) dimension: $crate::lib::marker::PhantomData<D>,
pub(super) unit: N,
pub(super) unit: $crate::lib::marker::PhantomData<N>,
pub(super) style: DisplayStyle,
}

Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9abc39e

Please sign in to comment.