Rust comments: Difference between revisions

From wikinotes
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 23: Line 23:
= Doc Comments =
= Doc Comments =
<blockquote>
<blockquote>
There are two styles of doc-comments:
<syntaxhighlight lang="rust">
<syntaxhighlight lang="rust">
/// doc-comment for following item (ex: java style)
//! document enclosing item (typically used for crates, modules)
fn foo() {
    println!("hi")
}


fn foo() {
/// document following item (typically used for objects, functions)
    //! doc-comment for enclosing item (ex: python style)
    println!("bye")
}
</syntaxhighlight>
</syntaxhighlight>
For more details, see [[rust documentation]].
</blockquote><!-- Doc Comments -->
</blockquote><!-- Doc Comments -->

Latest revision as of 21:17, 9 February 2023

Regular Comments

// inline comment
/* multiline
 * comment
 */

Annotation Comments

Variable assignments can be annotated

// This number is used because...
let magic_number = 123;

Doc Comments

There are two styles of doc-comments:

//! document enclosing item (typically used for crates, modules)

/// document following item (typically used for objects, functions)

For more details, see rust documentation.