stevenrwalter

Untitled

Jan 20th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. enum MyEnum {
  2.         MyEnumA = 1,
  3.         MyEnumB = 2,
  4. }
  5.  
  6. impl enum_set::CLike for MyEnum {
  7.         fn to_uint(&self) -> uint {
  8.                 *self as uint
  9.         }
  10.  
  11.         fn from_uint(u : uint) -> MyEnum {
  12.                 if (u == (MyEnumA as uint)) {
  13.                         MyEnumA
  14.                 } else {
  15.                         MyEnumB
  16.                 }
  17.         }
  18. }
  19.  
  20. type MyEnumSet = enum_set::EnumSet<MyEnum>;
  21.  
  22. fn main () {
  23.         let (port, chan) = Chan::new();
  24.         let (num_port, num_chan) = SharedChan::new();
  25.         let bar : uint = 0xdeadbeef;
  26.         let mut foo : MyEnumSet = enum_set::EnumSet::empty();
  27.  
  28.         for i in range(0,8 * 4) {
  29.                 let bit = bar & (1 << i);
  30.                 if (bit != 0) {
  31.                         let e : MyEnum = enum_set::CLike::from_uint(bit);
  32.                         foo.add(e);
  33.                 }
  34.         }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment