2 releases

0.1.1 Sep 9, 2023
0.1.0 Aug 20, 2021

#159 in Value formatting

30 downloads per month
Used in 8 crates (7 directly)

MIT/Apache

26KB
391 lines

indent-rs

A type and associated traits to enable display of hierarcical structures with appropriate indentation.

Examples

use indent_display::{Indenter, NullOptions, DefaultIndentedDisplay};
let mut ind = Indenter::new(&std::io::stdout(), "  ", &NullOptions {});
"banana\n".indent(&mut ind);
panic("argh");

Usage

Add this to your Cargo.toml:

[dependencies]
indent-display = "0.1.0"

Releases

Release notes are available in RELEASES.md.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Indent

This is a fairly simple indented display system designed for standard library (not simply core) applications.

use indent_display::{Indenter, NullOptions, DefaultIndentedDisplay, IndentedDisplay};
let mut stdout = std::io::stdout();
let mut ind = Indenter::new(&mut stdout, "  ", &NullOptions {});
"Not indented\n".indent(&mut ind);
{
let mut sub = ind.sub();
"Indented once with two spaces\n".indent(&mut ind);
}
{
let mut sub = ind.push("...");
"Indented once with three dots\n".indent(&mut ind);
{
let mut sub = sub.push("***");
"Indented with three dots and three stars\nAnd so is this".indent(&mut ind);
}
{
let mut sub = sub.sub();
"Indented with three dots and two spaces stars\nAnd so is this".indent(&mut ind);
}
}
"Not indented\n".indent(&mut ind);

!

No runtime deps