Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ macro_rules! quantity {
pub enum Units {
$(#[allow(clippy::empty_docs)] // macros cannot expand to enum variants
#[doc=$plural]
$unit($unit),)+
$unit,)+
}

impl Units {
Expand All @@ -172,7 +172,7 @@ macro_rules! quantity {
#[allow(dead_code)]
pub fn abbreviation(&self) -> &'static str {
match self {
$(Units::$unit(_) => $abbreviation,)+
$(Units::$unit => $abbreviation,)+
}
}

Expand All @@ -181,7 +181,7 @@ macro_rules! quantity {
#[allow(dead_code)]
pub fn singular(&self) -> &'static str {
match self {
$(Units::$unit(_) => $singular,)+
$(Units::$unit => $singular,)+
}
}

Expand All @@ -190,13 +190,13 @@ macro_rules! quantity {
#[allow(dead_code)]
pub fn plural(&self) -> &'static str {
match self {
$(Units::$unit(_) => $plural,)+
$(Units::$unit => $plural,)+
}
}
}

static ALL_UNITS: &[Units] = &[
$(Units::$unit($unit),)+
$(Units::$unit,)+
];

/// Iterate over all defined units for this quantity.
Expand Down
18 changes: 9 additions & 9 deletions src/tests/quantities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ fn plural() {

#[test]
fn units_abbreviation() {
assert_eq!("km", length::Units::kilometer(kilometer).abbreviation());
assert_eq!("m", length::Units::meter(meter).abbreviation());
assert_eq!("kg", mass::Units::kilogram(kilogram).abbreviation());
assert_eq!("km", length::Units::kilometer.abbreviation());
assert_eq!("m", length::Units::meter.abbreviation());
assert_eq!("kg", mass::Units::kilogram.abbreviation());
}

#[test]
fn units_singular() {
assert_eq!("kilometer", length::Units::kilometer(kilometer).singular());
assert_eq!("meter", length::Units::meter(meter).singular());
assert_eq!("kilogram", mass::Units::kilogram(kilogram).singular());
assert_eq!("kilometer", length::Units::kilometer.singular());
assert_eq!("meter", length::Units::meter.singular());
assert_eq!("kilogram", mass::Units::kilogram.singular());
}

#[test]
fn units_plural() {
assert_eq!("kilometers", length::Units::kilometer(kilometer).plural());
assert_eq!("meters", length::Units::meter(meter).plural());
assert_eq!("kilograms", mass::Units::kilogram(kilogram).plural());
assert_eq!("kilometers", length::Units::kilometer.plural());
assert_eq!("meters", length::Units::meter.plural());
assert_eq!("kilograms", mass::Units::kilogram.plural());
}

#[test]
Expand Down