#string #multi-line #utilities

dev trim-margin

一个用于通过检测其边距来帮助布局多行字符串的工具包

1 个不稳定版本

使用旧的Rust 2015

0.1.0 2018年1月13日

值格式化中有235

Download history 852/week @ 2023-12-07 1054/week @ 2023-12-14 845/week @ 2023-12-21 1278/week @ 2023-12-28 2807/week @ 2024-01-04 2634/week @ 2024-01-11 3136/week @ 2024-01-18 2802/week @ 2024-01-25 2281/week @ 2024-02-01 3208/week @ 2024-02-08 4579/week @ 2024-02-15 3882/week @ 2024-02-22 3397/week @ 2024-02-29 3300/week @ 2024-03-07 2527/week @ 2024-03-14 4287/week @ 2024-03-21

每月下载量14,047
5 个工具包中使用

Apache-2.0

10KB
71

trim-margin: 简单的多行字符串布局

Build Status Crates.io

该工具包旨在简化Rust中多行字符串的使用。在Rust中嵌入多行字符串时,所有空白、制表符等都被保留,即使它们只是为了使代码布局更美观。

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!("-----------------------");
}

trim-margin工具包通过在多行字符串中引入边距来支持您进行适当的布局。通过在多行字符串中引入边距,trim_margin方法可以过滤掉不需要的空白和空行。

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);
}

无运行时依赖