3 Doc comments are very useful for big projects that require documentation. When
4 running [Rustdoc][1], these are the comments that get compiled into
5 documentation. They are denoted by a `///`, and support [Markdown][2].
7 ```rust,editable,ignore,mdbook-runnable
10 /// A human being is represented here
12 /// A person must have a name, no matter how much Juliet may hate it
17 /// Returns a person with the name given them
21 /// * `name` - A string slice that holds the name of the person
26 /// // You can have rust code between fences inside the comments
27 /// // If you pass --test to Rustdoc, it will even test it for you!
29 /// let person = Person::new("name");
31 pub fn new(name: &str) -> Person {
33 name: name.to_string(),
37 /// Gives a friendly hello!
39 /// Says "Hello, [name]" to the `Person` it is called on.
40 pub fn hello(& self) {
41 println!("Hello, {}!", self.name);
46 let john = Person::new("John");
52 To run the tests, first build the code as a library, then tell rustdoc where
53 to find the library so it can link it into each doctest program:
56 $ rustc doc.rs --crate-type lib
57 $ rustdoc --test --extern doc="libdoc.rlib" doc.rs
60 (When you run `cargo test` on a library crate, Cargo will automatically
61 generate and run the correct rustc and rustdoc commands.)
63 [1]: https://doc.rust-lang.org/book/documentation.html
64 [2]: https://en.wikipedia.org/wiki/Markdown