#format #help #lazy #macro #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

#724 in Rust patterns

Download history 163/week @ 2022-12-01 139/week @ 2022-12-08 126/week @ 2022-12-15 55/week @ 2022-12-22 43/week @ 2022-12-29 81/week @ 2023-01-05 83/week @ 2023-01-12 72/week @ 2023-01-19 245/week @ 2023-01-26 126/week @ 2023-02-02 116/week @ 2023-02-09 123/week @ 2023-02-16 61/week @ 2023-02-23 310/week @ 2023-03-02 122/week @ 2023-03-09 28/week @ 2023-03-16

542 downloads per month
Used in 5 crates (4 directly)

MIT/Apache

12KB
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

~155KB