#text #align #justify #friend #left-align #right-align #center-align

text_align

A crate that provides a single trait for various alignments of text

6 releases

0.3.1 Dec 29, 2021
0.3.0 Dec 29, 2021
0.2.0 Dec 27, 2021
0.1.2 Dec 26, 2021

#4 in #friend

GPL-3.0-only

17KB
283 lines

text_align

A Rust crate that provides a single trait for various alignments of text

use text_align::TextAlign;

fn main() {
    assert_eq!(
        "                          Hello my dearest friend!".left_align(50),
        "Hello my dearest friend!                          "
    );

    assert_eq!(
        "Hello my dearest friend!".right_align(50),
        "                          Hello my dearest friend!"
    );

    assert_eq!(
        "Hello my dearest friend!".center_align(50),
        "             Hello my dearest friend!             "
    );

    assert_eq!(
        "Hello my dearest friend!".justify(50),
        "Hello          my          dearest         friend!"
    );

    assert_eq!(
        "Hello          my          dearest         friend!".dejustify(2),
        "Hello my dearest friend!"
    );
}

lib.rs:

use text_align::TextAlign;
assert_eq!(
    "                          Hello my dearest friend!".left_align(50),
    "Hello my dearest friend!                          "
);

assert_eq!(
    "Hello my dearest friend!".right_align(50),
    "                          Hello my dearest friend!"
);

assert_eq!(
    "Hello my dearest friend!".center_align(50),
    "             Hello my dearest friend!             "
);

assert_eq!(
    "Hello my dearest friend!".justify(50),
    "Hello          my          dearest         friend!"
);

assert_eq!(
    "Hello          my          dearest         friend!".dejustify(2),
    "Hello my dearest friend!"
);

Dependencies

~2.2–3MB
~53K SLoC