#line #break #wrap

linebreak

A library for breaking a given text into lines within a specified width

4 releases (2 breaking)

0.3.1 Jul 29, 2024
0.3.0 Jul 28, 2024
0.2.0 Mar 14, 2024
0.1.0 Mar 10, 2024

#334 in Text processing

Download history 232/week @ 2024-07-25 188/week @ 2024-08-01 89/week @ 2024-08-08 1/week @ 2024-08-15 3/week @ 2024-08-22 68/week @ 2024-08-29 1/week @ 2024-09-05 22/week @ 2024-09-12 17/week @ 2024-09-19 48/week @ 2024-09-26 7/week @ 2024-10-03 88/week @ 2024-10-10 11/week @ 2024-10-17

99 downloads per month
Used in cliargs

MIT license

73KB
1.5K SLoC

linebreak-rust crate.io doc.rs CI Status MIT License

A library for breaking a given text into lines within a specified width. This library also supports per-line indentation.

Install

In Cargo.toml, write this crate as a dependency.

[dependencies]
linebreak = "0.3.1"

Usage

The usage example of LineIter struct in this crate is as follows:

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

The output of the above code is as follows:

....:....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.

Supporting Rust versions

This crate supports Rust 1.67.1 or later.

% 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

License

Copyright (C) 2024 Takayuki Sato

This program is free software under MIT License.
See the file LICENSE in this distribution for more details.

Dependencies

~11–47MB
~705K SLoC