mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-28 06:59:11 +00:00
add chapter [Docs and Comments]
This commit is contained in:
54
practices/doc-comments/src/lib.rs
Normal file
54
practices/doc-comments/src/lib.rs
Normal file
@ -0,0 +1,54 @@
|
||||
//! # Doc comments
|
||||
//!
|
||||
//! A library for showing how to use doc comments
|
||||
|
||||
pub mod compute;
|
||||
|
||||
/// Add one to the given value and return a new value
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let arg = 5;
|
||||
/// let answer = doc_comments::add_one(arg);
|
||||
///
|
||||
/// assert_eq!(6, answer);
|
||||
/// ```
|
||||
pub fn add_one(x: i32) -> i32 {
|
||||
x + 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Add two to the given value and return a new value
|
||||
|
||||
# Examples
|
||||
|
||||
```
|
||||
let arg = 5;
|
||||
let answer = doc_comments::add_two(arg);
|
||||
|
||||
assert_eq!(7, answer);
|
||||
```
|
||||
*/
|
||||
pub fn add_two(x: i32) -> i32 {
|
||||
x + 2
|
||||
}
|
||||
|
||||
|
||||
/// Add three to the given value and return a [`Option`] type
|
||||
pub fn add_three(x: i32) -> Option<i32> {
|
||||
Some(x + 3)
|
||||
}
|
||||
|
||||
mod a {
|
||||
/// Add four to the given value and return a [`Option`] type
|
||||
/// [`crate::MySpecialFormatter`]
|
||||
pub fn add_four(x: i32) -> Option<i32> {
|
||||
Some(x + 4)
|
||||
}
|
||||
}
|
||||
|
||||
struct MySpecialFormatter;
|
||||
|
||||
|
Reference in New Issue
Block a user