Skip to content

Commit

Permalink
Add unittest example to rustdoc (#1276)
Browse files Browse the repository at this point in the history
Fixes #1275

---------

Co-authored-by: Martin Geisler <[email protected]>
  • Loading branch information
nyurik and mgeisler authored Sep 29, 2023
1 parent 1c43db1 commit c894ea3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/basic-syntax/rustdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

<details>

Expand Down

0 comments on commit c894ea3

Please sign in to comment.