Code Monkey home page Code Monkey logo

trim-margin's Introduction

trim-margin: easy layouting of multi-line strings

Build Status Documentation 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);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.