Skip to content

Commit

Permalink
Update documentation for show! itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Sep 5, 2024
1 parent cab3eb9 commit 046574f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
16 changes: 16 additions & 0 deletions examples/doc_macro_show.rs
Original file line number Diff line number Diff line change
@@ -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="!");
}
9 changes: 9 additions & 0 deletions examples/doc_macro_show.txt
Original file line number Diff line number Diff line change
@@ -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!
15 changes: 7 additions & 8 deletions src/write/macros.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
);
}

0 comments on commit 046574f

Please sign in to comment.