1 unstable release

0.9.0 Jun 5, 2023

#25 in #produce

Download history 174/week @ 2024-03-14 254/week @ 2024-03-21 440/week @ 2024-03-28 282/week @ 2024-04-04 246/week @ 2024-04-11 238/week @ 2024-04-18 413/week @ 2024-04-25 392/week @ 2024-05-02 258/week @ 2024-05-09 310/week @ 2024-05-16 297/week @ 2024-05-23 318/week @ 2024-05-30 353/week @ 2024-06-06 1645/week @ 2024-06-13 1898/week @ 2024-06-20 1128/week @ 2024-06-27

5,093 downloads per month
Used in 6 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