Просмотр исходного кода

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
Родитель
Сommit
67ea47a457
1 измененных файлов с 17 добавлено и 2 удалено
  1. 17 2
      rust/book/src/main.rs

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

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
fn inc(x: i32) -> i32 {
15
fn inc(x: i32) -> i32 {
2
    if x == 42 {
16
    if x == 42 {
3
        return 42
17
        return 42
7
}
21
}
8
22
9
fn main() {
23
fn main() {
10
    let x = 5;
24
    let x = 5; // x: i32
11
25
12
    println!("Hello, World!");
26
    println!("Hello, World!");
13
    if x == 42 {
27
    if x == 42 { // 42 is important
14
        println!("It's THE ANSWER!");
28
        println!("It's THE ANSWER!");
15
    } else {
29
    } else {
16
        println!("Meh, it's just a number, {}.", x);
30
        println!("Meh, it's just a number, {}.", x);
17
    }
31
    }
18
32
33
    // let's call some functions
19
    let n = 10;
34
    let n = 10;
20
    println!("inc({}) = {}", n, inc(n));
35
    println!("inc({}) = {}", n, inc(n));
21
    println!("inc(42) = {}", inc(42));
36
    println!("inc(42) = {}", inc(42));