Crates.io | strim |
lib.rs | strim |
version | |
source | src |
created_at | 2024-07-15 22:44:28.287979 |
updated_at | 2024-07-15 22:44:28.287979 |
description | Macro to trim whitespace from string literals |
homepage | |
repository | https://codeberg.org/petervaro/strim |
max_upload_size | |
id | 1304403 |
size | 0 |
strim
This crate provides a single procedural macro that removes all blank lines and leading and trailing whitespace from a string literal.
Rust's 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 unindent (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!\"");
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.
The simplest and quickest way to see the result of your changes is to use the
tests
project included in this repository, i.e.
$ cd tests/
$ 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 tests/
$ cargo test --features compile-errors
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.