Support all bitwise operations on flags

This commit is contained in:
J.C. Moyer
2014-04-26 01:01:16 -04:00
parent 4f76df1316
commit 57063fd3c6
+18
View File
@@ -63,6 +63,12 @@ macro_rules! flag_type(
}
}
impl ::std::ops::Not<$typename> for $typename {
fn not(&self) -> $typename {
$typename { bits: !self.bits }
}
}
impl ::std::ops::BitAnd<$typename, $typename> for $typename {
fn bitand(&self, rhs: &$typename) -> $typename {
$typename { bits: self.bits & rhs.bits }
@@ -81,6 +87,18 @@ macro_rules! flag_type(
}
}
impl ::std::ops::Shl<u32, $typename> for $typename {
fn shl(&self, rhs: &u32) -> $typename {
$typename { bits: self.bits << *rhs }
}
}
impl ::std::ops::Shr<u32, $typename> for $typename {
fn shr(&self, rhs: &u32) -> $typename {
$typename { bits: self.bits >> *rhs }
}
}
$(
pub static $name: $typename = $typename { bits: $value };
)+