#lazy-evaluation #help #wrap #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

#78 in #wrap

Download history 66/week @ 2024-05-18 85/week @ 2024-05-25 583/week @ 2024-06-01 765/week @ 2024-06-08 101/week @ 2024-06-15 132/week @ 2024-06-22 39/week @ 2024-06-29 101/week @ 2024-07-06 180/week @ 2024-07-13 453/week @ 2024-07-20 1663/week @ 2024-07-27 464/week @ 2024-08-03 60/week @ 2024-08-10 101/week @ 2024-08-17 166/week @ 2024-08-24 183/week @ 2024-08-31

574 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

~225KB