5 releases (breaking)

0.6.0 Aug 13, 2024
0.5.0 Aug 12, 2024
0.4.0 Jul 26, 2024
0.3.0 Jul 26, 2024
0.1.0 Jul 15, 2024

#1456 in Development tools

Download history 127/week @ 2024-07-27 244/week @ 2024-08-10 21/week @ 2024-08-17 7/week @ 2024-09-14 44/week @ 2024-09-28 1/week @ 2024-10-05 2/week @ 2024-10-12

332 downloads per month

GPL-3.0-or-later

26KB
589 lines

strim

status-badge

This crate provides a single procedural macro that removes all blank lines and leading and trailing whitespace from a string, byte-string, and C-string literals.

Rationale

Rust's string (byte-string, and C-string) literals are very convenient to use when it comes to breaking them into multiple lines by utilising the \ character, e.g.

let string = "\
    Hello,\
    World!\
";
assert_eq!(string, "Hello,World!");

However when one is forced to work with raw-literals, the \ character cannot be employed anymore to un-break and un-indent (i.e. trim) the lines. This is the main use-case where the strim::trim macro shines.

use strim::trim;

let string = trim!(r#"
    "Hello,
     World!"
"#);
assert_eq!(string, "\"Hello,World!\"");

Documentation

For more detailed explanation how the trim macro can be used, please consult its documentation: https://docs.rs/strim/0.6.0/strim/macro.trim.html.

Installation

Add the following to your Cargo.toml:

[dependencies]
strim = "~0.6.0"

Or use:

$ cargo add strim@~0.6.0

Bug Reports and Feature Requests

If you find something that doesn't work as expected and you wish to report it, or if you would like to submit a feature request, please do both of these in the 'issues' section of the original repository on Codeberg.

Development and Contribution

The simplest and quickest way to see the result of your changes is to use the dummy project included in this repository, i.e.

$ cd dummy/
$ cargo test

All invalid cases must produce easy to read, correct, and properly referring compile errors, i.e. they should underline and complain about the relevant bits which are incorrect. The tests which result in such compile errors are all hidden under the compile-errors feature.

$ cd dummy/
$ cargo test --features compile-errors

Various Rust Versions

The project uses <[u8]>::trim_ascii for byte-string trimming, however, that method has only been implemented since 1.80.0. Therefore it also implements the same functionality conditionally. For this reason, it should be tested with that version and the one before it.

Note: Eventually this complexity will be removed in later versions, when strim is more or less considered complete, so that the last version of it which still provides the alternative implementation would have most (if not all) of the features later versions have.

$ ./scripts/test.sh local

License

Copyright ©2024 Peter Varo

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses.

Dependencies

~200–620KB
~15K SLoC