4 releases

0.1.3 May 1, 2023
0.1.2 Jan 26, 2023
0.1.1 Jan 25, 2023
0.1.0 Jan 25, 2023

#114 in Value formatting

Download history 1014/week @ 2024-03-14 733/week @ 2024-03-21 844/week @ 2024-03-28 984/week @ 2024-04-04 1079/week @ 2024-04-11 877/week @ 2024-04-18 1058/week @ 2024-04-25 1071/week @ 2024-05-02 740/week @ 2024-05-09 818/week @ 2024-05-16 783/week @ 2024-05-23 1232/week @ 2024-05-30 1197/week @ 2024-06-06 1160/week @ 2024-06-13 892/week @ 2024-06-20 550/week @ 2024-06-27

4,013 downloads per month
Used in 6 crates (4 directly)

MIT license

23KB
404 lines

runtime-format

Formatting, but processed at runtime.

use runtime_format::{FormatArgs, FormatKey, FormatKeyError};
use core::fmt;

impl FormatKey for DateTime {
    fn fmt(&self, key: &str, f: &mut fmt::Formatter<'_>) -> Result<(), FormatKeyError> {
        use core::fmt::Write;
        match key {
            "year"    => write!(f, "{}", self.year()).map_err(FormatKeyError::Fmt),
            "month"   => write!(f, "{}", self.short_month_name()).map_err(FormatKeyError::Fmt),
            "day"     => write!(f, "{}", self.day()).map_err(FormatKeyError::Fmt),
            "hours"   => write!(f, "{}", self.hours()).map_err(FormatKeyError::Fmt),
            "minutes" => write!(f, "{}", self.minutes()).map_err(FormatKeyError::Fmt),
            "seconds" => write!(f, "{}", self.seconds()).map_err(FormatKeyError::Fmt),
            _ => Err(FormatKeyError::UnknownKey),
        }
    }
}
let now = DateTime::now();
let fmt = "{month} {day} {year} {hours}:{minutes}:{seconds}";
let args = FormatArgs::new(fmt, &now);

// Outputs "Jan 25 2023 16:27:53"
println!("{args}");

Dependencies

~65KB