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

functions

types must be specified, i.e. types are only inferred locally.  `return`
returns early, using it at the end of a function is not idiomatic.
Lucas Stadler лет назад: 10
Родитель
Сommit
fc13416f4d
1 измененных файлов с 13 добавлено и 0 удалено
  1. 13 0
      rust/book/src/main.rs

+ 13 - 0
rust/book/src/main.rs

1
fn inc(x: i32) -> i32 {
2
    if x == 42 {
3
        return 42
4
    }
5
6
    x + 1
7
}
8
1
fn main() {
9
fn main() {
2
    let x = 5;
10
    let x = 5;
3
11
7
    } else {
15
    } else {
8
        println!("Meh, it's just a number, {}.", x);
16
        println!("Meh, it's just a number, {}.", x);
9
    }
17
    }
18
19
    let n = 10;
20
    println!("inc({}) = {}", n, inc(n));
21
    println!("inc(42) = {}", inc(42));
22
    println!("inc(43) = {}", inc(43));
10
}
23
}