#display #fmt #Formatter #error

indenter

A formatter wrapper that indents the text, designed for error display impls

7 releases

0.3.2 Jan 4, 2021
0.3.1 Dec 21, 2020
0.3.0 May 17, 2020
0.2.0 May 7, 2020
0.1.1 Feb 28, 2020

#1 in #fmt

Download history 4771/week @ 2020-10-02 3954/week @ 2020-10-09 4708/week @ 2020-10-16 6469/week @ 2020-10-23 6204/week @ 2020-10-30 9212/week @ 2020-11-06 11279/week @ 2020-11-13 13095/week @ 2020-11-20 12463/week @ 2020-11-27 11914/week @ 2020-12-04 9335/week @ 2020-12-11 10001/week @ 2020-12-18 5464/week @ 2020-12-25 9974/week @ 2021-01-01 15051/week @ 2021-01-08 13394/week @ 2021-01-15

36,150 downloads per month
Used in 80 crates (5 directly)

MIT/Apache

13KB
205 lines

indenter

Build Status Latest Version Rust Documentation

A wrapper for the fmt::Write objects that efficiently appends indentation after every newline.

This type is intended primarily for writing error reporters that gracefully format error messages that span multiple lines.

Setup

Add this to your Cargo.toml:

[dependencies]
indenter = "0.2"

Example

use std::error::Error;
use std::fmt::{self, Write};
use indenter::indented;

struct ErrorReporter<'a>(&'a dyn Error);

impl fmt::Debug for ErrorReporter<'_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut source = Some(self.0);
        let mut i = 0;

        while let Some(error) = source {
            writeln!(f)?;
            write!(indented(f).ind(i), "{}", error)?;

            source = error.source();
            i += 1;
        }

        Ok(())
    }
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps