Skip to content

Commit

Permalink
Add concatdoc docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 29, 2023
1 parent 476b937 commit 24a804e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,24 @@ fn main() {

## Formatting macros

The indoc crate exports four additional macros to substitute conveniently for
The indoc crate exports five additional macros to substitute conveniently for
the standard library's formatting macros:

- `formatdoc!($fmt, ...)` — equivalent to `format!(indoc!($fmt), ...)`
- `printdoc!($fmt, ...)` — equivalent to `print!(indoc!($fmt), ...)`
- `eprintdoc!($fmt, ...)` — equivalent to `eprint!(indoc!($fmt), ...)`
- `writedoc!($dest, $fmt, ...)` — equivalent to `write!($dest, indoc!($fmt), ...)`
- `concatdoc!(...)` — equivalent to `concat!(...)` with each string literal wrapped in `indoc!`

```rust
use indoc::printdoc;
use indoc::{concatdoc, printdoc};

const HELP: &str = concatdoc! {"
Usage: ", env!("CARGO_BIN_NAME"), " [options]
Options:
-h, --help
"};

fn main() {
printdoc! {"
Expand Down
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,30 @@
//!
//! # Formatting macros
//!
//! The indoc crate exports four additional macros to substitute conveniently
//! The indoc crate exports five additional macros to substitute conveniently
//! for the standard library's formatting macros:
//!
//! - `formatdoc!($fmt, ...)` — equivalent to `format!(indoc!($fmt), ...)`
//! - `printdoc!($fmt, ...)` — equivalent to `print!(indoc!($fmt), ...)`
//! - `eprintdoc!($fmt, ...)` — equivalent to `eprint!(indoc!($fmt), ...)`
//! - `writedoc!($dest, $fmt, ...)` — equivalent to `write!($dest, indoc!($fmt), ...)`
//! - `concatdoc!(...)` — equivalent to `concat!(...)` with each string literal wrapped in `indoc!`
//!
//! ```
//! use indoc::printdoc;
//! # macro_rules! env {
//! # ($var:literal) => {
//! # "example"
//! # };
//! # }
//! #
//! use indoc::{concatdoc, printdoc};
//!
//! const HELP: &str = concatdoc! {"
//! Usage: ", env!("CARGO_BIN_NAME"), " [options]
//!
//! Options:
//! -h, --help
//! "};
//!
//! fn main() {
//! printdoc! {"
Expand Down

0 comments on commit 24a804e

Please # to comment.