Explorar el Código

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 %!s(int64=10) %!d(string=hace) años
padre
commit
fc13416f4d
Se han modificado 1 ficheros con 13 adiciones y 0 borrados
  1. 13 0
      rust/book/src/main.rs

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

@ -1,3 +1,11 @@
1
fn inc(x: i32) -> i32 {
2
    if x == 42 {
3
        return 42
4
    }
5
6
    x + 1
7
}
8
1 9
fn main() {
2 10
    let x = 5;
3 11
@ -7,4 +15,9 @@ fn main() {
7 15
    } else {
8 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
}