inform 0.2.3

Another rust indentation formatter
Documentation

inform: INdent FORMatter

A std::fmt::Formatter drop-in replacement designed for formatting structured data such as AST nodes.

use std::fmt::{self, Display, Write};

use inform::fmt::IndentFormatter;

struct TestIndentFormatter;
impl Display for TestIndentFormatter {
    fn fmt(&self, f: &mut fmt::Formatter -> fmt::Result {
        let mut f = IndentFormatter::new(f, 2);
        writeln!(f, "hello\ngoodbye")?;
        f.increase_indent();
        writeln!(f, "hello\ngoodbye")?;
        f.decrease_indent();
        writeln!(f, "hello\ngoodbye")
    }
}

#[test]
fn test_indent_formatter() {
    assert_eq!(
        "hello\ngoodbye\n  hello\n  goodbye\nhello\ngoodbye\n",
        TestIndentFormatter.to_string()
    );
}

Alternatives

The following crates are alternatives that I found did not fit my use case.

License

A copy of the MIT License is provided in the LICENSE file.