File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 3838//! }
3939//! ~~~
4040//!
41+ //! The generated `struct`s can also be extended with type and trait implementations:
42+ //!
43+ //! ~~~rust
44+ //! #[feature(phase)];
45+ //! #[phase(syntax)] extern crate collections;
46+ //!
47+ //! use std::fmt;
48+ //!
49+ //! bitflags!(Flags: u32 {
50+ //! FlagA = 0x00000001,
51+ //! FlagB = 0x00000010
52+ //! })
53+ //!
54+ //! impl Flags {
55+ //! pub fn clear(&mut self) {
56+ //! self.bits = 0; // The `bits` field can be accessed from within the
57+ //! // same module where the `bitflags!` macro was invoked.
58+ //! }
59+ //! }
60+ //!
61+ //! impl fmt::Show for Flags {
62+ //! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63+ //! write!(f.buf, "hi!")
64+ //! }
65+ //! }
66+ //!
67+ //! fn main() {
68+ //! let mut flags = FlagA | FlagB;
69+ //! flags.clear();
70+ //! assert!(flags.is_empty());
71+ //! assert_eq!(format!("{}", flags), ~"hi!");
72+ //! }
73+ //! ~~~
74+ //!
4175//! # Operators
4276//!
4377//! The following operator traits are implemented for the generated `struct`:
You can’t perform that action at this time.
0 commit comments