| Crates.io | docstr |
| lib.rs | docstr |
| version | 0.4.4 |
| created_at | 2025-09-18 20:03:40.93581+00 |
| updated_at | 2025-09-21 17:56:47.671873+00 |
| description | Ergonomic multi-line string literals |
| homepage | |
| repository | https://github.com/nik-rev/docstr |
| max_upload_size | |
| id | 1845254 |
| size | 52,663 |
docstrThis crate provides a procedural macro for ergonomically creating multi-line string literals.
It is an alternative to indoc.
[dependencies]
docstr = "0.4"
Note: docstr does not have any dependencies such as syn or quote, so compile-speeds are very fast.
docstr! takes documentation comments as arguments and converts them into a string
use docstr::docstr;
let hello_world_in_c: &'static str = docstr!(
/// #include <stdio.h>
///
/// int main(int argc, char **argv) {
/// printf("hello world\n");
/// return 0;
/// }
);
assert_eq!(hello_world_in_c, r#"#include <stdio.h>
int main(int argc, char **argv) {
printf("hello world\n");
return 0;
}"#)
docstr! can pass the generated string to any macro:
use docstr::docstr;
let age = 21;
let name = "Bob";
let colors = ["red", "green", "blue"];
let greeting: String = docstr!(format!
//^^^^^^^ the generated string is passed to `format!`
// as the 1st argument
/// Hello, my name is {name}.
/// I am {age} years old!
///
/// My favorite color is: {}
// anything after the doc comments is passed directly at the end
colors[1]
);
//^ above expands to: format!("...", colors[1])
assert_eq!(greeting, "Hello, my name is Bob.\nI am 21 years old!\n\nMy favorite color is: green");
Injecting arguments before the generated string is also possible.
docstr!(write! w
/// Hello, world!
);
Expands to:
write!(w, "Hello, world!");