From dfc080f26a8f8f5039043906eed902e5acf3970c Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Wed, 18 Sep 2024 16:30:54 +0530 Subject: [PATCH] feat: is_dividable compilation error and print unsupported quantity type --- src/types/quantity.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/types/quantity.rs b/src/types/quantity.rs index 14dea3b..b24c9e0 100644 --- a/src/types/quantity.rs +++ b/src/types/quantity.rs @@ -46,7 +46,7 @@ impl FromStr for QuantityUnit { MILLI_LITER => Ok(Self::MilliLiter), LITER => Ok(Self::Liter), MILLI_GRAM => Ok(Self::Milligram), - _ => Err("Currency unsupported".into()), + _ => Err(format!("Quantity unsupported: {s}")), } } } @@ -74,6 +74,15 @@ impl QuantityPart { } } } + + pub fn is_dividable(&self) -> bool { + match self.unit { + QuantityUnit::Kilogram | QuantityUnit::Liter | QuantityUnit::Gram => true, + QuantityUnit::Milligram | QuantityUnit::MilliLiter | QuantityUnit::DiscreteNumber => { + false + } + } + } } #[derive(