Skip to content
Open
Changes from 4 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
22 changes: 19 additions & 3 deletions src/si/volume.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Volume (base unit cubic meter, m³).
#![allow(deprecated)] // rust warns of our own deprecations

quantity! {
/// Volume (base unit cubic meter, m³).
Expand Down Expand Up @@ -63,7 +64,11 @@ quantity! {
@cubic_inch: 1.638_706_E-5; "in³", "cubic inch", "cubic inches";
@cubic_mile: 4.168_182_E9; "mi³", "cubic mile", "cubic miles";
@cubic_yard: 7.645_549_E-1; "yd³", "cubic yard", "cubic yards";
@cup: 2.365_882_E-4; "cup", "cup", "cups";
#[doc = "US cups. Deprecated."]
#[deprecated(note = "please use suffixed unit e.g. _us, _metric")]
@cup: 2.365_882_E-4; "cup (US)", "cup (US)", "cups (US)";
@cup_us: 2.365_882_E-4; "cup (US)", "cup (US)", "cups (US)";
Copy link

@OJFord OJFord Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 'US customary' - there is also 'US legal' (240ml precisely) so it's probably worth being clear what it is even if not also providing the other.

(There's also the old UK imperial system based cup size, I believe it's the same number of floz as US customary cup, but since UK floz != US floz it works out to be about 284ml. It's obsolete though, and I think was never really that common (vs. floz & pints even if they work out to round cups or fractions) so maybe not worth adding.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks for the suggestion.

Modified cup_us to be cup_us_customary and added a cup_us_legal at 240mL, and also changed unit names in 6c716a8

@cup_metric: prefix!(milli) * prefix!(milli) * 250.0; "cup", "cup", "cups";
@fluid_ounce: 2.957_353_E-5; "fl oz", "fluid ounce", "fluid ounces";
@fluid_ounce_imperial: 2.841_306_E-5; "fl oz (UK)", "Imperial fluid ounce", "Imperial fluid ounces";
@gallon_imperial: 4.546_09_E-3; "gal (UK)", "Imperial gallon", "Imperial gallons";
Expand Down Expand Up @@ -97,8 +102,19 @@ quantity! {
@quart_dry: 1.101_221_E-3; "dry qt", "dry quart", "dry quarts";
@quart_liquid: 9.463_529_E-4; "liq qt", "liquid quart", "liquid quarts";
@stere: 1.0_E0; "st", "stere", "steres";
@tablespoon: 1.478_676_E-5; "tbsp", "tablespoon", "tablespoons";
@teaspoon: 4.928_922_E-6; "tsp", "teaspoon", "teaspoons";
#[deprecated(note = "please use suffixed unit e.g. _us, _aus, _metric")]
#[doc = "US tablespoons. Deprecated."] // doc is required here, see macro arms in unit.rs L368 vs L374
@tablespoon: 1.478_676_E-5; "tbsp (US)", "tablespoon (US)", "tablespoons (US)";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what to do with the naming changes ­— technically this could be considered breaking if a library user is relying on matching the abbreviations or names.

However since this is the SI module I assume that the metric units should take priority.

#[deprecated(note = "please use suffixed unit e.g. _us, _metric")]
#[doc = "US teaspoons. Deprecated."]
@teaspoon: 4.928_922_E-6; "tsp (US)", "teaspoon (US)", "teaspoons (US)";
@tablespoon_us: 1.478_676_E-5; "tbsp (US)", "US tablespoon", "US tablespoons";
@teaspoon_us: 4.928_922_E-6; "tsp (US)", "US teaspoon", "US teaspoons";
@tablespoon_metric: prefix!(milli) * prefix!(milli) * 15.0; "tbsp", "tablespoon", "tablespoons";
@teaspoon_metric: prefix!(milli) * prefix!(milli) * 5.0; "tsp", "teaspoon", "teaspoons";
// note: Australian tablespoons are 20mL (so one teaspoon is 1/4 of a tbsp) instead of the
// typical 15mL. There is no difference in the Australian teaspoon.
@tablespoon_aus: prefix!(milli) * prefix!(milli) * 20.0; "tbsp (AU)", "tablespoon (AU)", "tablespoons (AU)";
@register_ton: 2.831_685_E0; "RT", "register ton", "register tons";
}
}
Expand Down