Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum MyEnum {
- MyEnumA = 1,
- MyEnumB = 2,
- }
- impl enum_set::CLike for MyEnum {
- fn to_uint(&self) -> uint {
- *self as uint
- }
- fn from_uint(u : uint) -> MyEnum {
- if (u == (MyEnumA as uint)) {
- MyEnumA
- } else {
- MyEnumB
- }
- }
- }
- type MyEnumSet = enum_set::EnumSet<MyEnum>;
- fn main () {
- let (port, chan) = Chan::new();
- let (num_port, num_chan) = SharedChan::new();
- let bar : uint = 0xdeadbeef;
- let mut foo : MyEnumSet = enum_set::EnumSet::empty();
- for i in range(0,8 * 4) {
- let bit = bar & (1 << i);
- if (bit != 0) {
- let e : MyEnum = enum_set::CLike::from_uint(bit);
- foo.add(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment