View difference between Paste ID: 5VyNJRx4 and FJ0NXLWD
SHOW: | | - or go back to the newest paste.
1
enum MyEnum {
2
        MyEnumA = 1,
3
        MyEnumB = 2,
4
	MyEnumEmpty;
5
}
6
7
impl enum_set::CLike for MyEnum {
8
        fn to_uint(&self) -> uint {
9
                *self as uint
10
        }
11
12
        fn from_uint(u : uint) -> MyEnum {
13
                if (u == (MyEnumA as uint)) {
14
                        MyEnumA
15-
                        MyEnumB
15+
		} else if (u == (MyEnumB as uint)) {
16
			MyEnumB
17
                } else {
18
                        MyEnumEmpty
19
                }
20
        }
21
}
22
23
type MyEnumSet = enum_set::EnumSet<MyEnum>;
24
25
fn main () {
26
        let (port, chan) = Chan::new();
27
        let (num_port, num_chan) = SharedChan::new();
28
        let bar : uint = 0xdeadbeef;
29
        let mut foo : MyEnumSet = enum_set::EnumSet::empty();
30
31
        for i in range(0,8 * 4) {
32
                let bit = bar & (1 << i);
33
                if (bit != 0) {
34
                        let e : MyEnum = enum_set::CLike::from_uint(bit);
35
                        foo.add(e);
36
                }
37
        }
38
}