RustDocumentation


Introduction

Rust's compiler has several handy features to make documenting your project quick and easy. You can use compiler lints to enforce documentation for each function, and have tests built in to your examples.

Syntax

  • /// Outer documentation comment (applies to the item below)

  • //! Inner documentation comment (applies to the enclosing item)

  • cargo doc # Generates documentation for this library crate.

  • cargo doc --open # Generates documentation for this library crate and open browser.

  • cargo doc -p CRATE # Generates documentation for the specified crate only.

  • cargo doc --no-deps # Generates documentation for this library and no dependencies.

  • cargo test # Runs unit tests and documentation tests.

Remarks

This section of the 'Rust Book' may contain useful information about documentation and documentation tests.

Documentation comments can be applied to:

  • Modules
  • Structs
  • Enums
  • Methods
  • Functions
  • Traits and Trait Methods