#dynamic #static #string-format

no-std runtime-format

rust library for formatting dynamic strings

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

#262 in Date and time

Download history 1790/week @ 2025-10-11 2930/week @ 2025-10-18 1891/week @ 2025-10-25 2232/week @ 2025-11-01 2424/week @ 2025-11-08 1942/week @ 2025-11-15 1787/week @ 2025-11-22 2063/week @ 2025-11-29 1515/week @ 2025-12-06 1727/week @ 2025-12-13 2869/week @ 2025-12-20 1969/week @ 2025-12-27 2700/week @ 2026-01-03 3337/week @ 2026-01-10 2740/week @ 2026-01-17 3431/week @ 2026-01-24

12,403 downloads per month
Used in 9 crates (5 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

~34KB