-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression.rs
54 lines (49 loc) · 1.15 KB
/
expression.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
fn main() {
//Empty block returns ()
let block_expr = {};
println!("{:?}", block_expr);
let a = 10;
let b = { a + 1 };
let hash = {
//Read some file form disk then store them in hash map
// and then returns it
//let mut hashmap = HashMap::new();
//hashmap
};
//Here the return type is optional
fn expr(x: bool) -> () {
if x {
//Note there is no semicoln here
println!("This variant is Bool::True")
} else {
println!("This variant is Bool::False")
}
}
//we can use external variable
let a = 10;
//We can put any expression that evaluates to bool
expr({
//Also local variable
let b = 15;
a < b
});
expr(1 > 6);
use self::Bool::{False, True};
//Because of PartialEq
expr(True == False);
//Because of PartialOrd
expr(False > True);
enum Empty{
Nonne,
Nonejk,
Noned,
jhk,
}
println!("{}",std::mem::size_of::<Empty>());
}
//Field ordering from zero if not specified
#[derive(PartialEq, PartialOrd)]
enum Bool {
True,
False,
}