#line #break #wrap

linebreak

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

2 unstable releases

0.2.0 Mar 14, 2024
0.1.0 Mar 10, 2024

#262 in Text processing

Download history 84/week @ 2024-03-04 182/week @ 2024-03-11 10/week @ 2024-03-18 40/week @ 2024-04-01

316 downloads per month

MIT license

69KB
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.2.0"

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

~10–51MB
~719K SLoC