#lazy-evaluation #wrap #help #macro

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

#76 in #wrap

Download history 473/week @ 2024-07-22 1692/week @ 2024-07-29 409/week @ 2024-08-05 47/week @ 2024-08-12 102/week @ 2024-08-19 209/week @ 2024-08-26 202/week @ 2024-09-02 201/week @ 2024-09-09 223/week @ 2024-09-16 121/week @ 2024-09-23 98/week @ 2024-09-30 33/week @ 2024-10-07 64/week @ 2024-10-14 47/week @ 2024-10-21 31/week @ 2024-10-28 31/week @ 2024-11-04

179 downloads per month
Used in 6 crates (5 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

~230KB