https://github.com/jharrilim/dedent-macro-rs
Proc macro for dedenting string literals
https://github.com/jharrilim/dedent-macro-rs
dedent macro rust strings
Last synced: 5 months ago
JSON representation
Proc macro for dedenting string literals
- Host: GitHub
- URL: https://github.com/jharrilim/dedent-macro-rs
- Owner: jharrilim
- License: mit
- Created: 2024-01-31T03:11:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-31T04:41:36.000Z (over 2 years ago)
- Last Synced: 2024-12-31T09:42:09.167Z (over 1 year ago)
- Topics: dedent, macro, rust, strings
- Language: Rust
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dedent-macro
This crate provides a simple compile-time macro to dedent strings.
Useful for keeping consistent indentation within code.
Before:
```rust
fn write_win_status(x: bool) {
let s = if x {
"
Congratulations!
You won!
"
} else {
"
Uh oh,
try again!
"
}
println!("{s}");
}
```
after:
```rust
fn write_win_status(x: bool) {
let s = if x {
dedent!("
Congratulations!
You won!
")
} else {
dedent!("
Uh oh,
try again!
")
}
println!("{s}");
}
let s =
assert_eq!(s, "foo\nbar");
```