Sfoglia il codice sorgente

comments

`///` are doc comments.  however, they don't work for binaries, so we'll
have to wait a bit until `cargo doc` will generate something.

the book doesn't mention multiline comments, but they do exist.  (`/**`
are doc block comments.)

doc comments are also just a special syntax for `#[doc="..."]`
attributes.
Lucas Stadler 10 anni fa
parent
commit
67ea47a457
1 ha cambiato i file con 17 aggiunte e 2 eliminazioni
  1. 17 2
      rust/book/src/main.rs

+ 17 - 2
rust/book/src/main.rs

@ -1,3 +1,17 @@
1
/// `inc` is a function that increments it's argument, except if the
2
/// argument is 42.
3
///
4
/// # Arguments
5
///
6
/// * `x` - The number to increment
7
///
8
/// # Examples
9
///
10
/// ```rust
11
/// inc(3)  == 4
12
/// inc(42) == 42
13
/// inc(99) == 100
14
/// ```
1 15
fn inc(x: i32) -> i32 {
2 16
    if x == 42 {
3 17
        return 42
@ -7,15 +21,16 @@ fn inc(x: i32) -> i32 {
7 21
}
8 22
9 23
fn main() {
10
    let x = 5;
24
    let x = 5; // x: i32
11 25
12 26
    println!("Hello, World!");
13
    if x == 42 {
27
    if x == 42 { // 42 is important
14 28
        println!("It's THE ANSWER!");
15 29
    } else {
16 30
        println!("Meh, it's just a number, {}.", x);
17 31
    }
18 32
33
    // let's call some functions
19 34
    let n = 10;
20 35
    println!("inc({}) = {}", n, inc(n));
21 36
    println!("inc(42) = {}", inc(42));