Lucas Stadler 10 lat temu
rodzic
commit
9a3c52989c
1 zmienionych plików z 14 dodań i 1 usunięć
  1. 14 1
      rust/book/src/main.rs

+ 14 - 1
rust/book/src/main.rs

@ -34,6 +34,14 @@ enum Number {
34 34
    NaN
35 35
}
36 36
37
fn print_num_type(num: Number) {
38
    println!("{}", match num {
39
        Number::Integer(_) => "integer",
40
        Number::Float(_) => "float",
41
        Number::NaN => "not a number"
42
    })
43
}
44
37 45
fn main() {
38 46
    let x = 5; // x: i32
39 47
@ -73,5 +81,10 @@ fn main() {
73 81
    let i: Number = Number::Integer(3);
74 82
    let f: Number = Number::Float(3.1415);
75 83
    let n: Number = Number::NaN;
76
    println!("Here are some numbers: {:?}, {:?} and {:?}", i, f, n)
84
    println!("Here are some numbers: {:?}, {:?} and {:?}", i, f, n);
85
86
    // match
87
    print_num_type(i);
88
    print_num_type(f);
89
    print_num_type(n);
77 90
}