Rust documentation

From wikinotes
Revision as of 21:16, 9 February 2023 by Will (talk | contribs) (Created page with "= Generate/View Docs = <blockquote> <syntaxhighlight lang="bash"> cargo doc --open # build, and view docs (current project, and it's dependencies) </syntaxhighlight> </blockquote><!-- Document --> = Syntax = <blockquote> == Example == <blockquote> doc-comments are written in markdown, and code-blocks default to rust as the language.<br> assertions written in doc-comments are run with your test-suite. <syntaxhighlight lang="rust"> //! # My Module (doc-comment for e...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Generate/View Docs

cargo doc --open  # build, and view docs (current project, and it's dependencies)

Syntax

Example

doc-comments are written in markdown, and code-blocks default to rust as the language.
assertions written in doc-comments are run with your test-suite.

//! # My Module (doc-comment for enclosing item)
//!
//! This module does foo, and bar, and baz.
//! (can be used for functions, but not idiomatic)
//! (often used for crates)


/// Feeds the cat  (doc-comment for following-item)
///
/// # Examples
///
/// ```
/// let name = "mycat";
/// let success = feed(name);
/// assert!(success);
/// ```
fn feed_cat(name: &str) -> bool {
    println!("hi")
}

Common Headers

It's customary to write the following headers:

Examples sample of use
Panics scenarios when this method panics
Errors the error types that may be returned
Safety if function is unsafe, why