https://github.com/sunsided/merge-whitespace-rs
Procedural macros for merging whitespace in const contexts
https://github.com/sunsided/merge-whitespace-rs
graphql macros procedural-macro rust text-processing
Last synced: 4 months ago
JSON representation
Procedural macros for merging whitespace in const contexts
- Host: GitHub
- URL: https://github.com/sunsided/merge-whitespace-rs
- Owner: sunsided
- License: other
- Created: 2024-05-14T11:33:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-24T08:58:11.000Z (about 1 year ago)
- Last Synced: 2025-11-06T00:09:14.858Z (9 months ago)
- Topics: graphql, macros, procedural-macro, rust, text-processing
- Language: Rust
- Homepage: https://crates.io/crates/merge-whitespace
- Size: 101 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# merge_whitespace
[](https://crates.io/crates/merge-whitespace)
[](https://crates.io/crates/merge-whitespace)

[![Safety Dance][safety-image]][safety-link]
[](https://docs.rs/merge-whitespace/)
[](https://codecov.io/gh/sunsided/merge-whitespace-rs)
This crate contains procedural macros for removing multiple consecutive whitespaces from a
given string literal, replacing them with a single space.
## Example
The example below uses an optional quotation character to keep quoted text ranges un-merged, as well as
an optional escape character to ensure that quotation character literals are kept as-is.
```rust
use merge_whitespace::merge_whitespace;
const QUERY: &str = merge_whitespace!(r#"
query {
users (limit: 1, filter: "bought a 12\" vinyl
named \"spaces in space \"") {
id
name
todos(order_by: {created_at: desc}, limit: 5) {
id
title
}
}
}
"#,
quote_char = '"',
escape_char = '\\');
#[test]
fn test() {
assert_eq!(QUERY, r#"query { users (limit: 1, filter: "bought a 12\" vinyl
named \"spaces in space \"") { id name todos(order_by: {created_at: desc}, limit: 5) { id title } } }"#);
}
```
Alternatively, the `merge_whitespace_utils::merge_whitespace` function can be used to process variable input.
[safety-image]: https://img.shields.io/badge/unsafe-forbidden-success.svg
[safety-link]: https://github.com/rust-secure-code/safety-dance/