#line #break #wrap

linebreak

一个将给定文本按指定宽度断开成行的库

4 个版本 (2 个重大更改)

0.3.1 2024 年 7 月 29 日
0.3.0 2024 年 7 月 28 日
0.2.0 2024 年 3 月 14 日
0.1.0 2024 年 3 月 10 日

文本处理 中排名 315

Download history 16/week @ 2024-05-20 83/week @ 2024-07-22 241/week @ 2024-07-29 183/week @ 2024-08-05

每月下载量 507
cliargs 中使用

MIT 许可证

73KB
1.5K SLoC

linebreak-rust crate.io doc.rs CI 状态 MIT 许可证

一个将给定文本按指定宽度断开成行的库。此库还支持每行的缩进。

安装

Cargo.toml 中,将此 crate 作为依赖项写入。

[dependencies]
linebreak = "0.3.1"

用法

此 crate 中 LineIter 结构的用法示例如下

use linebreak::LineIter;

fn main() {
    let text = "Welcome to The Rust Programming Language, an introductory \
      book about Rust. The Rust programming language helps you write faster, \
      more reliable software. High-level ergonomics and low-level control are \
      often at odds in programming language design; Rust challenges that \
      conflict. Through balancing powerful technical capacity and a great \
      developer experience, Rust gives you the option to control low-level \
      details (such as memory usage) without all the hassle traditionally \
      associated with such control.";

    let mut iter = LineIter::new(&text, 80);
    iter.set_indent("_______");

    println!("....:....1....:....2....:....3....:....4....:....5....:....6\
              ....:....7....:....8");
    while let Some(line) = iter.next() {
        println!("{}", line);
    }
}

以上代码的输出如下

....:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8
_______Welcome to The Rust Programming Language, an introductory book about
_______Rust. The Rust programming language helps you write faster, more reliable
_______software. High-level ergonomics and low-level control are often at odds
_______in programming language design; Rust challenges that conflict. Through
_______balancing powerful technical capacity and a great developer experience,
_______Rust gives you the option to control low-level details (such as memory
_______usage) without all the hassle traditionally associated with such control.

支持的 Rust 版本

此 crate 支持 Rust 1.67.1 或更高版本。

% cargo msrv
Fetching index
Determining the Minimum Supported Rust Version (MSRV) for toolchain x86_64-apple-darwin
Using check command cargo check

Check for toolchain '1.66.1-x86_64-apple-darwin' failed with:
┌──────────────────────────────────────────────────────────────────────────────┐
│ error: package `icu_list v1.4.0` cannot be built because it requires rustc   │
│ 1.67 or newer, while the currently active rustc version is 1.66.1            │
│ Either upgrade to rustc 1.67 or newer, or use                                │
│ cargo update -p icu_list@1.4.0 --precise ver                                 │
│ where `ver` is the latest version of `icu_list` supporting rustc 1.66.1      │
└──────────────────────────────────────────────────────────────────────────────┘
Check for toolchain '1.71.1-x86_64-apple-darwin' succeeded
Check for toolchain '1.68.2-x86_64-apple-darwin' succeeded
Check for toolchain '1.67.1-x86_64-apple-darwin' succeeded
   Finished The MSRV is: 1.67.1   █████████████████████████████████████ 00:00:03

许可证

版权所有 (C) 2024 Takayuki Sato

本程序是在 MIT 许可证下免费的软件。
有关更多详细信息,请参阅此分布中的 LICENSE 文件。

依赖项

~12–48MB
~714K SLoC