From 24a804e0cf34cb53f0958af9216cbb7c24b8052c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 29 Jan 2023 14:28:49 -0800 Subject: [PATCH] Add concatdoc docs --- README.md | 12 ++++++++++-- src/lib.rs | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d9f4787..391e159 100644 --- a/README.md +++ b/README.md @@ -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! {" diff --git a/src/lib.rs b/src/lib.rs index 4f62496..c5de6b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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! {"