Rust provides two types of documentation comments: inner documentation comments and outer documentation comments. Examples of each are provided below.
Inner Documentation Comments
mod foo {
//! Inner documentation comments go *inside* an item (e.g. a module or a
//! struct). They use the comment syntax //! and must go at the top of the
//! enclosing item.
struct Bar {
pub baz: i64
//! This is invalid. Inner comments must go at the top of the struct,
//! and must not be placed after fields.
}
}
Outer Documentation Comments
/// Outer documentation comments go *outside* the item that they refer to.
/// They use the syntax /// to distinguish them from inner comments.
pub enum Test {
Success,
Fail(Error)
}