#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

#43 in #wrap

Download history 205/week @ 2023-11-19 74/week @ 2023-11-26 248/week @ 2023-12-03 53/week @ 2023-12-10 63/week @ 2023-12-17 363/week @ 2023-12-24 97/week @ 2023-12-31 54/week @ 2024-01-07 113/week @ 2024-01-14 79/week @ 2024-01-21 22/week @ 2024-01-28 70/week @ 2024-02-04 38/week @ 2024-02-11 49/week @ 2024-02-18 87/week @ 2024-02-25 158/week @ 2024-03-03

340 downloads per month
Used in 8 crates (7 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

~210KB