4个稳定版本

1.2.0 2021年11月4日
1.1.0 2021年10月12日
1.0.1 2021年10月9日
1.0.0 2021年10月8日

#549Unix API

MIT 许可证

6KB
66

Leftpad

CircleCI dependency status Docs

一个Rust包,用于使用字符左填充字符串。

受“left-pad”NPM包(及其删除后的灾难)启发。

支持的平台

  • Unix(已在FreeBSD、Linux和macOS上测试过)
  • Windows
    • cmd.exe
    • Powershell

示例

use leftpad_rs::{pad,pad_char,pad_with};

fn main() {
    let s = "foo";

    println!("{}", pad(s, 5));
    let s1 = match pad_char(s, 6, ' ')) {
        Ok(s) => s,
        Err(e) => Err("Error: {}", e)
    };
    println!("{:?}", s1);
    
    // You can use pad_with() too now.

crates.io

您可以通过将以下内容添加到您的 Cargo.toml 中来在项目中使用此包

[dependencies]
leftpad-rs = "1.1.0"

然后您可以在自己的crates中使用它。

无运行时依赖