<commit_before>use std::borrow::Cow::Borrowed;
use std::borrow::Cow;
use std::fmt;

#[derive(Debug, Clone, PartialEq)]
pub struct NumberValue<'a> {
    pub scalar:   f32,
    pub unit:     Option<Cow<'a, str>>,
    pub computed: bool,
}

impl<'a, 'b> NumberValue<'a> {
    pub fn from_scalar(num: f32) -> NumberValue<'a> {
        NumberValue {
            scalar:   num,
            unit:     None,
            computed: false,
        }
    }

    #[cfg(test)]
    pub fn computed(num: f32) -> NumberValue<'a> {
        NumberValue {
            scalar:   num,
            unit:     None,
            computed: true,
        }
    }

    pub fn with_units(num: f32, unit: Cow<'a, str>) -> NumberValue<'a> {
        NumberValue {
            scalar:   num,
            unit:     Some(unit),
            computed: false,
        }
    }

    pub fn into_owned(self) -> NumberValue<'b> {
        NumberValue {
            scalar: self.scalar,
            unit: match self.unit {
                Some(u) => Some(u.into_owned().into()),
                None => None,
            },
            computed: self.computed,
        }
    }

}

impl<'a> fmt::Display for NumberValue<'a> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}{}", self.scalar, self.unit.clone().unwrap_or(Borrowed("")))
    }
}
<commit_msg>Make printing number values a bit nicer<commit_after>use std::borrow::Cow::*;
use std::borrow::Cow;
use std::fmt;

#[derive(Debug, Clone, PartialEq)]
pub struct NumberValue<'a> {
    pub scalar:   f32,
    pub unit:     Option<Cow<'a, str>>,
    pub computed: bool,
}

impl<'a, 'b> NumberValue<'a> {
    pub fn from_scalar(num: f32) -> NumberValue<'a> {
        NumberValue {
            scalar:   num,
            unit:     None,
            computed: false,
        }
    }

    #[cfg(test)]
    pub fn computed(num: f32) -> NumberValue<'a> {
        NumberValue {
            scalar:   num,
            unit:     None,
            computed: true,
        }
    }

    pub fn with_units(num: f32, unit: Cow<'a, str>) -> NumberValue<'a> {
        NumberValue {
            scalar:   num,
            unit:     Some(unit),
            computed: false,
        }
    }

    pub fn into_owned(self) -> NumberValue<'b> {
        NumberValue {
            scalar: self.scalar,
            unit: match self.unit {
                Some(u) => Some(u.into_owned().into()),
                None => None,
            },
            computed: self.computed,
        }
    }

    pub fn unit_string(&self) -> &str {
        match self.unit {
            Some(Borrowed(ref b)) => b,
            Some(Owned(ref o))    => o,
            None                  => "",
        }
    }
}

impl<'a> fmt::Display for NumberValue<'a> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}{}", self.scalar, self.unit_string())
    }
}

{'fraction_non_alphanumeric': 0.15029503644567857, 'fraction_numerical': 0.0055536272127733426, 'mean_word_length': 1.6513339466421344, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4087580', 'n_tokens_mistral': 935, 'n_tokens_neox': 950, 'n_words': 207}