diff --git a/src/parser.rs b/src/parser.rs index 63880c6..2ea8f4a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -95,6 +95,7 @@ fn parse_suffix(input: &str) -> IResult<&str, (Format, Scale)> { tag("Ti"), tag("Pi"), tag("Ei"), + tag("n"), tag("m"), tag("k"), tag("M"), @@ -115,6 +116,7 @@ fn parse_suffix(input: &str) -> IResult<&str, (Format, Scale)> { "Ei" => (Format::BinarySI, Scale::Exa), // "m" => (Format::DecimalSI, Scale::Milli), + "n" => (Format::DecimalSI, Scale::Nano), "" => (Format::DecimalSI, Scale::One), "k" => (Format::DecimalSI, Scale::Kilo), "M" => (Format::DecimalSI, Scale::Mega), diff --git a/src/scale.rs b/src/scale.rs index f350b0c..34c9dd7 100644 --- a/src/scale.rs +++ b/src/scale.rs @@ -2,6 +2,7 @@ /// scales are omitted for mathematical simplicity. #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Default)] pub(crate) enum Scale { + Nano, Milli, #[default] One, @@ -25,6 +26,7 @@ impl From<&Scale> for i32 { fn from(value: &Scale) -> Self { // https://en.wikipedia.org/wiki/Kilobyte match value { + Scale::Nano => -3, Scale::Milli => -1, Scale::One => 0, Scale::Kilo => 1, @@ -42,6 +44,7 @@ impl TryFrom for Scale { fn try_from(value: i32) -> Result { match value { + -3 => Ok(Scale::Nano), -1 => Ok(Scale::Milli), 0 => Ok(Scale::One), 1 => Ok(Scale::Kilo), diff --git a/src/utils.rs b/src/utils.rs index 2dd4b7d..c1e778d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,6 +4,7 @@ use crate::{format::Format, scale::Scale}; pub(crate) fn scale_format_to_string(scale: &Scale, format: &Format) -> String { match format { Format::BinarySI => match scale { + Scale::Nano => "n".to_owned(), Scale::Milli => "".to_owned(), Scale::One => "".to_owned(), Scale::Kilo => "Ki".to_owned(), @@ -14,6 +15,7 @@ pub(crate) fn scale_format_to_string(scale: &Scale, format: &Format) -> String { Scale::Exa => "Ei".to_owned(), }, Format::DecimalSI => match scale { + Scale::Nano => "n".to_owned(), Scale::Milli => "m".to_owned(), Scale::One => "".to_owned(), Scale::Kilo => "k".to_owned(),