diff --git a/examples/doc_macro_show.rs b/examples/doc_macro_show.rs new file mode 100644 index 0000000..8ffb648 --- /dev/null +++ b/examples/doc_macro_show.rs @@ -0,0 +1,16 @@ +fn main() { + use iof::show; + + // This will write "42\n" to the standard output. + show!(42); + // This will write "42 Hello, World!\n" to the standard output. + show!(42, "Hello, World!"); + // This will write "42 Hello, World! 1 2 3 4\n" to the standard output. + show!(42, "Hello, World!", [1, 2, 3, 4]); + // This will write "42 Hello, World! 1 2 3 4 1 2 3 4\n" to the standard output. + show!(42, "Hello, World!", [1, 2, 3, 4], [[1, 2], [3, 4]]); + // This will write "42, Hello, World!, 1 2 3 4, 1 2 3 4\n" to the standard output. + show!(42, "Hello, World!", [1, 2, 3, 4], [[1, 2], [3, 4]]; sep=", "); + // This will write "42, Hello, World!, 1 2 3 4, 1 2 3 4!" to the standard output. + show!(42, "Hello, World!", [1, 2, 3, 4], [[1, 2], [3, 4]]; sep=", ", end="!"); +} diff --git a/examples/doc_macro_show.txt b/examples/doc_macro_show.txt new file mode 100644 index 0000000..eb539ad --- /dev/null +++ b/examples/doc_macro_show.txt @@ -0,0 +1,9 @@ +42 +42 Hello, World! +42 Hello, World! 1 2 3 4 +42 Hello, World! 1 2 3 4 1 2 +3 4 +42, Hello, World!, 1 2 3 4, 1 2 +3 4 +42, Hello, World!, 1 2 3 4, 1 2 +3 4! \ No newline at end of file diff --git a/src/write/macros.rs b/src/write/macros.rs index 074d8de..5e6ec6b 100644 --- a/src/write/macros.rs +++ b/src/write/macros.rs @@ -1,14 +1,13 @@ /// Write the given expression into [standard output](std::io::Stdout) using [WriteInto]. /// -/// ```rust -/// use iof::show; +/// You can configure the writer using the following options: +/// +/// - `sep`: Separator between values. Default is `" "`. +/// - `end`: End of the output. Default is `"\n"`. +/// - `buf`: Buffer to write into. Default is [standard output](crate::stdout). /// -/// show!(42); -/// show!(42, "Hello, World!"); -/// show!(42, "Hello, World!", [1, 2, 3, 4]); -/// show!(42, "Hello, World!", [1, 2, 3, 4], [[1, 2], [3, 4]]); -/// show!(42, "Hello, World!", [1, 2, 3, 4], [[1, 2], [3, 4]]; sep=", "); -/// show!(42, "Hello, World!", [1, 2, 3, 4], [[1, 2], [3, 4]]; sep=", ", end="!"); +/// ```rust +#[doc = include_str!("../../examples/doc_macro_show.rs")] /// ``` /// /// [WriteInto]: crate::WriteInto diff --git a/tests/test_bin.rs b/tests/test_bin.rs index 130448e..3ba5ab2 100644 --- a/tests/test_bin.rs +++ b/tests/test_bin.rs @@ -112,3 +112,13 @@ fn doc_get_line_some() { fn doc_show() { test_example("doc_show", "", include_str!("../examples/doc_show.txt")); } + +#[test] +#[cfg_attr(miri, ignore)] +fn doc_macro_show() { + test_example( + "doc_macro_show", + "", + include_str!("../examples/doc_macro_show.txt"), + ); +}