liveBook · Manning

Outer documentation

As explained in Idiomatic Rust

Outer documentation is Rust documentation attached to the outer scope of a source file or module using documentation comments beginning with //! .

Outer documentation attaches crate-level or module-level documentation to the surrounding scope. In Rust, comments beginning with //! document the outer scope, while /// documents the next item. section 6.11.2

Documenting a crate

Place top-level documentation at the beginning of src/lib.rs: //! # linkedlist crate //! //! This crate provides a simple linked list implementation. //! //! ## Example usage //! //! ```rust //! use linkedlist::LinkedList; //! let mut animals = LinkedList::new(); //! animals.append("chicken"); //! ``` The rendered crate page gives users a starting point and a runnable usage example. section 6.11.2

Use outer documentation when you need to:

  • Describe a crate’s purpose and its primary entry point. section 6.11.2
  • Include examples that rustdoc turns into integration tests. section 6.11.2
  • Regenerate documentation during editing with cargo watch -x doc. section 6.11.2
//! # linkedlist crate
//!
//! This crate provides a simple linked list implementation.
//!
//! The crate serves as a teaching example for the book [_Rust Advanced
//! Techniques_](https://www.manning.com/books/idiomatic-rust).
//!
//! ## Example usage
//!
//! ```rust
//! use linkedlist::LinkedList;
//!
//! let mut animals = LinkedList::new();
//! animals.append("chicken");
//! animals.append("ostrich");
//! animals.append("antelope");
//! animals.append("axolotl");
//! animals.append("okapi");
//! ```

Inspect the complete crate-level //! example, including its rendered usage code. section 6.11.2

How Idiomatic Rust covers it

How deep it goes
Defines //! and /// scope, demonstrates crate documentation, and explains automatic doc-example testing.
Examples
Uses a linked-list crate description, usage snippet, cargo test output, and cargo watch workflow.
What it assumes
Assumes basic Rust source-file and crate structure while teaching documentation-comment scope from the syntax upward.
What you can do after
Build crate documentation with //!, embed usage examples, and verify them through cargo test.
How it connects
Connects rustdoc with inner documentation, integration testing, and cargo test.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Idiomatic Rust. The section links point to the parts of the book it draws on.