1 个不稳定版本
使用旧的Rust 2015
0.1.0 | 2018年1月13日 |
---|
在值格式化中有235个
每月下载量14,047
在5 个工具包中使用
10KB
71 行
trim-margin: 简单的多行字符串布局
该工具包旨在简化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);
}