Skip to content

Commit

Permalink
add support for nanocpus
Browse files Browse the repository at this point in the history
  • Loading branch information
philgebhardt committed Jul 29, 2024
1 parent acb8cb0 commit 9d9cc66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions src/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -42,6 +44,7 @@ impl TryFrom<i32> for Scale {

fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
-3 => Ok(Scale::Nano),
-1 => Ok(Scale::Milli),
0 => Ok(Scale::One),
1 => Ok(Scale::Kilo),
Expand Down
2 changes: 2 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 9d9cc66

Please sign in to comment.