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

#90 in Value formatting

Download history 816/week @ 2024-01-08 711/week @ 2024-01-15 828/week @ 2024-01-22 1598/week @ 2024-01-29 1023/week @ 2024-02-05 1249/week @ 2024-02-12 1349/week @ 2024-02-19 1989/week @ 2024-02-26 2438/week @ 2024-03-04 2100/week @ 2024-03-11 775/week @ 2024-03-18 678/week @ 2024-03-25 808/week @ 2024-04-01 1114/week @ 2024-04-08 1071/week @ 2024-04-15 935/week @ 2024-04-22

4,027 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

~67KB