Читаем Rust by Example полностью

/// Says "Hello, [name]" to the `Person` it is called on.

pub fn hello(& self) {

println!("Hello, {}!", self.name);

}

}

fn main() {

let john = Person::new("John");

john.hello();

}

הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

To run the tests, first build the code as a library, then tell rustdoc where to find the library so it can link it into each doctest program:

$ rustc doc.rs --crate-type lib

$ rustdoc --test --extern doc="libdoc.rlib" doc.rs

<p id="doc_attributes"><strong><a l:href="#doc_attributes">Doc attributes</a></strong></p>

Below are a few examples of the most common #[doc] attributes used with rustdoc.

<p id="inline"><strong><a l:href="#inline">inline</a></strong></p>

Used to inline docs, instead of linking out to separate page.

#[doc(inline)]

pub use bar::Bar;

/// bar docs

mod bar {

/// the docs for Bar

pub struct Bar;

}

<p id="no_inline"><strong><a l:href="#no_inline">no_inline</a></strong></p>

Used to prevent linking out to separate page or anywhere.

// Example from libcore/prelude

#[doc(no_inline)]

pub use crate::mem::drop;

<p id="hidden"><strong><a l:href="#hidden">hidden</a></strong></p>

Using this tells rustdoc not to include this in documentation:

// Example from the futures-rs library

#[doc(hidden)]

pub use self::async_await::*;

הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

For documentation, rustdoc is widely used by the community. It's what is used to generate the std library docs.

<p id="see_also_75"><strong><a l:href="#see_also_75">See also:</a></strong></p>

   • The Rust Book: Making Useful Documentation Comments

   • The rustdoc Book

   • The Reference: Doc comments

   • RFC 1574: API Documentation Conventions

   • RFC 1946: Relative links to other items from doc comments (intra-rustdoc links)

   • Is there any documentation style guide for comments? (reddit)

<p id="playpen"><strong><a l:href="#playpen">Playpen</a></strong></p>

The Rust Playpen is a way to experiment with Rust code through a web interface. This project is now commonly referred to as Rust Playground.

<p id="using_it_with_mdbook"><strong><a l:href="#using_it_with_mdbook">Using it with</a><a l:href="#using_it_with_mdbook">mdbook</a></strong></p>

In mdbook, you can make code examples playable and editable.

fn main() {

println!("Hello World!");

}

Перейти на страницу:

Похожие книги