@@ -12,26 +12,27 @@ use bitflags::bitflags;
1212use std::fmt;
1313
1414bitflags! {
15+ #[derive(PartialEq, Debug, Copy, Clone)]
1516 struct MyFlags: u32 {
1617 const FLAG_A = 0b00000001;
1718 const FLAG_B = 0b00000010;
1819 const FLAG_C = 0b00000100;
19- const FLAG_ABC = Self::FLAG_A.bits
20- | Self::FLAG_B.bits
21- | Self::FLAG_C.bits;
20+ const FLAG_ABC = Self::FLAG_A.bits()
21+ | Self::FLAG_B.bits()
22+ | Self::FLAG_C.bits() ;
2223 }
2324}
2425
2526impl MyFlags {
2627 pub fn clear(&mut self) -> &mut MyFlags {
27- self.bits = 0;
28+ * self = MyFlags::empty();
2829 self
2930 }
3031}
3132
3233impl fmt::Display for MyFlags {
3334 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34- write!(f, "{:032b}", self.bits)
35+ write!(f, "{:032b}", self.bits() )
3536 }
3637}
3738
@@ -46,10 +47,6 @@ fn main() {
4647 let mut flags = MyFlags::FLAG_ABC;
4748 assert_eq!(format!("{}", flags), "00000000000000000000000000000111");
4849 assert_eq!(format!("{}", flags.clear()), "00000000000000000000000000000000");
49- assert_eq!(format!("{:?}", MyFlags::FLAG_B), "FLAG_B");
50- assert_eq!(format!("{:?}", MyFlags::FLAG_A | MyFlags::FLAG_B), "FLAG_A | FLAG_B");
50+ assert_eq!(format!("{:?}", MyFlags::FLAG_B), "MyFlags( FLAG_B) ");
51+ assert_eq!(format!("{:?}", MyFlags::FLAG_A | MyFlags::FLAG_B), "MyFlags( FLAG_A | FLAG_B) ");
5152}
52- ```
53-
54- [ `bitflags!` ] : https://docs.rs/bitflags/*/bitflags/macro.bitflags.html
55- [ `Display` ] : https://doc.rust-lang.org/std/fmt/trait.Display.html
0 commit comments