Skip to content

Commit

Permalink
chore: work towards better number formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 28, 2024
1 parent f26867e commit 362de7d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/metrics/delta.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use num_format::ToFormattedStr;
use std::fmt::{Debug, Display, Formatter, Write};

pub trait DeltaValue: Copy + Debug + Display {
Expand Down Expand Up @@ -140,6 +141,18 @@ pub trait DeltaTo {
fn delta_to(&mut self, other: &Self);
}

pub struct Formatted<T>(pub T);

impl<T: ToFormattedStr> Display for Formatted<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
use num_format::{Locale, ToFormattedString};

f.write_str(&self.0.to_formatted_string(&Locale::en))?;

Ok(())
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 362de7d

Please sign in to comment.