1 unstable release

0.9.0 Jun 5, 2023

#2663 in Rust patterns

Download history 1116/week @ 2024-07-03 1602/week @ 2024-07-10 1629/week @ 2024-07-17 1634/week @ 2024-07-24 1777/week @ 2024-07-31 1601/week @ 2024-08-07 1437/week @ 2024-08-14 2107/week @ 2024-08-21 1632/week @ 2024-08-28 1609/week @ 2024-09-04 1568/week @ 2024-09-11 1250/week @ 2024-09-18 14100/week @ 2024-09-25 9502/week @ 2024-10-02 2434/week @ 2024-10-09 2172/week @ 2024-10-16

28,556 downloads per month
Used in 7 crates (via starlark)

MIT/Apache

12KB
215 lines

Provides utilities to implement Display, which also provides an "alternate" display.

As an example of using these combinators:

use std::fmt;
use display_container::*;

struct MyItems(Vec<(String, i32)>);

impl fmt::Display for MyItems {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt_container(f, "{", "}",
            iter_display_chain(
                &["magic"],
                self.0.iter().map(|(k, v)| display_pair(k, "=", v))
            )
        )
    }
}

Would produce results such as:

{magic, hello=1, world=2}

For "normal" display, produces output like (with prefix="prefix[", suffix="]"):

prefix[] prefix[1] prefix[1, 2]

For "alternate" display, produces output like:

prefix[] prefix[ 1 ]

prefix[
  1,
  2
]

This doesn't propagate the flags on the Formatter other than alternate.

Dependencies

~66KB