From c894ea3517d1a79f2c03c8d24ffa06bfac097b4f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Sep 2023 02:40:24 -0400 Subject: [PATCH] Add unittest example to rustdoc (#1276) Fixes #1275 --------- Co-authored-by: Martin Geisler --- src/basic-syntax/rustdoc.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/basic-syntax/rustdoc.md b/src/basic-syntax/rustdoc.md index b42c73a22d6..ca6be198145 100644 --- a/src/basic-syntax/rustdoc.md +++ b/src/basic-syntax/rustdoc.md @@ -6,6 +6,11 @@ All language items in Rust can be documented using special `///` syntax. /// Determine whether the first argument is divisible by the second argument. /// /// If the second argument is zero, the result is false. +/// +/// # Example +/// ``` +/// assert!(is_divisible_by(42, 2)); +/// ``` fn is_divisible_by(lhs: u32, rhs: u32) -> bool { if rhs == 0 { return false; // Corner case, early return @@ -18,6 +23,7 @@ The contents are treated as Markdown. All published Rust library crates are automatically documented at [`docs.rs`](https://docs.rs) using the [rustdoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html) tool. It is idiomatic to document all public items in an API using this pattern. +Code snippets can document usage and will be used as unit tests.