stevenrwalter

Untitled

Jan 20th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. enum MyEnum {
  2.     MyEnumEmpty = 0;
  3.         MyEnumA = 1,
  4.         MyEnumB = 2,
  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.         } 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. }
Advertisement
Add Comment
Please, Sign In to add comment