#lazy-evaluation #macro #help #wrap

no-std format

A utility crate to make it easier to work with the formatter

9 releases

0.2.4 Apr 4, 2021
0.2.3 Sep 26, 2020
0.2.2 Apr 3, 2020
0.1.3 Apr 1, 2020

#128 in #wrap

Download history 95/week @ 2025-09-11 57/week @ 2025-09-18 81/week @ 2025-09-25 89/week @ 2025-10-02 33/week @ 2025-10-09 63/week @ 2025-10-16 56/week @ 2025-10-23 45/week @ 2025-10-30 45/week @ 2025-11-06 60/week @ 2025-11-13 49/week @ 2025-11-20 52/week @ 2025-11-27 38/week @ 2025-12-04 37/week @ 2025-12-11 64/week @ 2025-12-18 82/week @ 2025-12-25

228 downloads per month
Used in 7 crates (6 directly)

MIT/Apache

13KB
78 lines

Format

crates.io docs.rs license ci minimum supported rust version

A utility crate to make it easier to work with the formatter

Usage

Add dependency to your Cargo.toml:

[dependencies]
format = "0.2"

and use lazy_format macro:

struct Foo(usize);

impl Debug for Foo {
    fn fmt(&self, f: &mut Formatter) -> Result {
        let alternate = f.alternate();
        let bar = lazy_format!(|f| if alternate {
            write!(f, "{:#x}", self.0)
        } else {
            write!(f, "{:x}", self.0)
        });
        f.debug_tuple("Foo")
            .field(&format_args!("{}", bar))
            .finish()
    }
}

or one of format type:

struct Foo(usize);

impl Debug for Foo {
    fn fmt(&self, f: &mut Formatter) -> Result {
        let alternate = f.alternate();
        let bar = LowerHex(|f| {
            if alternate {
                write!(f, "{:#x}", self.0)
            } else {
                write!(f, "{:x}", self.0)
            }
        });
        f.debug_tuple("Foo")
            .field(&format_args!("{:x}", bar))
            .finish()
    }
}

Dependencies

~245KB