trim-margin

Crates.iotrim-margin
lib.rstrim-margin
version0.1.0
sourcesrc
created_at2018-01-13 23:20:56.875063
updated_at2018-01-13 23:20:56.875063
descriptionA utility crate to help with layouting multi-line strings by detecting their margin.
homepagehttps://github.com/mindsbackyard/trim-margin
repositoryhttps://github.com/mindsbackyard/trim-margin
max_upload_size
id46721
size20,476
corporate-engineering (github:yumemi-inc:corporate-engineering)

documentation

https://docs.rs/trim-margin

README

trim-margin: easy layouting of multi-line strings

Build Status Crates.io

This crate is intended to ease the use of multi-line strings in Rust. When embedding strings with multiple lines in Rust all whitespaces, tabs, etc. are preserved even if they are just used for layouting one's code nicely.

fn main() {
    println!("-----------------------");
    let misrepresented_multiline_string = "
        This is string
        spans over multiple lines,
        but its rendering preserves all whitespaces.

        Which is not what we usually intend in this case.
    ";
    println!("{}", misrepresented_multiline_string);
    println!("-----------------------");

    println!("-----------------------");
    let correctly_layouted_string = "For displaying
the a multiline strin properly
it would need to be layouted
like this.

Which is not very nice.";
    println!("{}", correctly_layouted_string);
    println!("-----------------------");
}

The trim-margin crate supports you with proper layouting. By introducing a margin in the multi-line string the trim_margin method can filter out unwanted whitespaces and blank lines.

extern crate trim_margin;
use trim_margin::MarginTrimmable;

fn main() {
    let multiline_string_with_margin = "
        |This string has a margin
        |indicated by the '|' character.
        |
        |The following method call will remove ...
        | * a blank first/last line
        | * blanks before the margin prefix
        | * the margin prefix itself
    ".trim_margin().unwrap();
    println!("{}", multiline_string_with_margin);
}
Commit count: 4

cargo fmt