• Home
  • Raw
  • Download

Lines Matching +full:format +full:- +full:extra +full:- +full:args

2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
11 //! A typesafe bitmask flag generator useful for sets of C-style bitmask flags.
37 //! assert_eq!((e1 - e2), Flags::A); // set difference
68 //! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
77 //! assert_eq!(format!("{}", flags), "hi!");
78 //! assert_eq!(format!("{:?}", Flags::A | Flags::B), "A | B");
79 //! assert_eq!(format!("{:?}", Flags::B), "B");
152 //! - `BitOr` and `BitOrAssign`: union
153 //! - `BitAnd` and `BitAndAssign`: intersection
154 //! - `BitXor` and `BitXorAssign`: toggle
155 //! - `Sub` and `SubAssign`: set difference
156 //! - `Not`: set complement
162 //! - `empty`: an empty set of flags
163 //! - `all`: the set of all defined flags
164 //! - `bits`: the raw value of the flags currently stored
165 //! - `from_bits`: convert from underlying bit representation, unless that
168 //! - `from_bits_truncate`: convert from underlying bit representation, dropping
170 //! - `from_bits_unchecked`: convert from underlying bit representation, keeping
173 //! - `is_empty`: `true` if no flags are currently stored
174 //! - `is_all`: `true` if currently set flags exactly equal all defined flags
175 //! - `intersects`: `true` if there are flags common to both `self` and `other`
176 //! - `contains`: `true` if all of the flags in `other` are contained within `self`
177 //! - `insert`: inserts the specified flags in-place
178 //! - `remove`: removes the specified flags in-place
179 //! - `toggle`: the specified flags will be inserted if not present, and removed
181 //! - `set`: inserts or removes the specified flags depending on the passed value
182 //! - `intersection`: returns a new set of flags, containing only the flags present
184 //! - `union`: returns a new set of flags, containing any flags present in
186 //! - `difference`: returns a new set of flags, containing all flags present in
189 //! - `symmetric_difference`: returns a new set of flags, containing all flags
192 //! - `complement`: returns a new set of flags, containing all flags which are
236 //! fn default() -> Flags {
307 /// assert_eq!((e1 - e2), Flags::A); // set difference
335 /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
344 /// assert_eq!(format!("{}", flags), "hi!");
345 /// assert_eq!(format!("{:?}", Flags::A | Flags::B), "A | B");
346 /// assert_eq!(format!("{:?}", Flags::B), "B");
355 $(#[$inner:ident $($args:tt)*])*
371 $(#[$inner $($args)*])*
391 $(#[$attr:ident $($args:tt)*])*
408 $(? #[$attr $($args)*])*
428 $(#[$attr:ident $($args:tt)*])*
434 fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
435 // This convoluted approach is to handle #[cfg]-based flag
447 fn $Flag(&self) -> bool { false }
459 $(? #[$attr $($args)*])*
460 fn $Flag(&self) -> bool {
497 fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
502 fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
507 fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
512 fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
520 $(#[$attr $($args)*])*
526 pub const fn empty() -> Self {
532 pub const fn all() -> Self {
536 $(#[$attr $($args)*])*
545 pub const fn bits(&self) -> $T {
552 pub const fn from_bits(bits: $T) -> $crate::_core::option::Option<Self> {
563 pub const fn from_bits_truncate(bits: $T) -> Self {
573 /// disallow extra bits for their bitflags type.
576 /// all bits correspond to a defined flag or that extra bits
579 pub const unsafe fn from_bits_unchecked(bits: $T) -> Self {
585 pub const fn is_empty(&self) -> bool {
591 pub const fn is_all(&self) -> bool {
597 pub const fn intersects(&self, other: Self) -> bool {
603 pub const fn contains(&self, other: Self) -> bool {
607 /// Inserts the specified flags in-place.
613 /// Removes the specified flags in-place.
619 /// Toggles the specified flags in-place.
644 /// [`ops::BitAnd`]: https://doc.rust-lang.org/std/ops/trait.BitAnd.html
647 pub const fn intersection(self, other: Self) -> Self {
661 /// [`ops::BitOr`]: https://doc.rust-lang.org/std/ops/trait.BitOr.html
664 pub const fn union(self, other: Self) -> Self {
673 /// It is also conceptually equivalent to the "bit-clear" operation:
676 /// This is equivalent to using the `-` operator (e.g.
677 /// [`ops::Sub`]), as in `flags - other`.
679 /// [`ops::Sub`]: https://doc.rust-lang.org/std/ops/trait.Sub.html
682 pub const fn difference(self, other: Self) -> Self {
686 /// Returns the [symmetric difference][sym-diff] between the flags
697 /// [sym-diff]: https://en.wikipedia.org/wiki/Symmetric_difference
698 /// [`ops::BitXor`]: https://doc.rust-lang.org/std/ops/trait.BitXor.html
701 pub const fn symmetric_difference(self, other: Self) -> Self {
711 /// between [`Self::all()`] and `self` (e.g. `Self::all() - self`)
717 /// [`ops::Not`]: https://doc.rust-lang.org/std/ops/trait.Not.html
720 pub const fn complement(self) -> Self {
731 fn bitor(self, other: $BitFlags) -> Self {
749 fn bitxor(self, other: Self) -> Self {
767 fn bitand(self, other: Self) -> Self {
785 fn sub(self, other: Self) -> Self {
803 fn not(self) -> Self {
817 fn from_iter<T: $crate::_core::iter::IntoIterator<Item=Self>>(iterator: T) -> Self {
837 // fn f() -> i32 { /* ... */ }
842 // fn f() -> i32 { /* ... */ }
946 #[doc = "> - Richard Feynman"]
969 const ANOTHER_FLAG = -1_i8;
1031 let extra = unsafe { Flags::from_bits_unchecked(0b1000) }; in test_from_bits_unchecked() localVariable
1042 (extra | Flags::empty()) in test_from_bits_unchecked()
1046 (extra | Flags::A) in test_from_bits_unchecked()
1049 let extra = unsafe { EmptyFlags::from_bits_unchecked(0b1000) }; in test_from_bits_unchecked() localVariable
1052 (extra | EmptyFlags::empty()) in test_from_bits_unchecked()
1074 let extra = unsafe { Flags::from_bits_unchecked(0b1000) }; in test_is_all() localVariable
1075 assert!(!extra.is_all()); in test_is_all()
1076 assert!(!(Flags::A | extra).is_all()); in test_is_all()
1077 assert!((Flags::ABC | extra).is_all()); in test_is_all()
1158 assert_eq!((e1 - e2), Flags::A); // set difference in test_operators()
1172 let extra = unsafe { Flags::from_bits_unchecked(0b1000) }; in test_operators_unchecked() localVariable
1173 let e1 = Flags::A | Flags::C | extra; in test_operators_unchecked()
1175 assert_eq!((e1 | e2), (Flags::ABC | extra)); // union in test_operators_unchecked()
1177 assert_eq!((e1 - e2), (Flags::A | extra)); // set difference in test_operators_unchecked()
1180 assert_eq!(e1 ^ e2, Flags::A | Flags::B | extra); // toggle in test_operators_unchecked()
1183 assert_eq!(e3, Flags::A | Flags::B | extra); in test_operators_unchecked()
1214 assert_eq!(ac.difference(bc), ac - bc); in test_set_ops_basic()
1215 assert_eq!(bc.difference(ac), bc - ac); in test_set_ops_basic()
1227 // These just test that these compile and don't cause use-site panics in test_set_ops_const()
1236 assert_eq!(DIFFERENCE, Flags::all() - Flags::A); in test_set_ops_const()
1238 assert_eq!(SYM_DIFFERENCE, (Flags::A | Flags::C) ^ (Flags::all() - Flags::A)); in test_set_ops_const()
1243 let extra = unsafe { Flags::from_bits_unchecked(0b1000) }; in test_set_ops_unchecked() localVariable
1244 let e1 = Flags::A.union(Flags::C).union(extra); in test_set_ops_unchecked()
1247 assert_eq!(e1.union(e2), (Flags::ABC | extra)); in test_set_ops_unchecked()
1249 assert_eq!(e1.difference(e2), Flags::A | extra); in test_set_ops_unchecked()
1253 assert_eq!(e1.symmetric_difference(e2), Flags::A | Flags::B | extra); // toggle in test_set_ops_unchecked()
1258 // Define a flag that contains gaps to help exercise edge-cases, in test_set_ops_exhaustive()
1261 // - when lhs and rhs both have different sets of unknown flags. in test_set_ops_exhaustive()
1262 // - unknown flags at both ends, and in the middle in test_set_ops_exhaustive()
1263 // - cases with "gaps". in test_set_ops_exhaustive()
1315 "wrong result: `{:?}` - `{:?}`", in test_set_ops_exhaustive()
1319 // Note: Difference is checked as both `a - b` and `b - a` in test_set_ops_exhaustive()
1323 "wrong result: `{:?}` - `{:?}`", in test_set_ops_exhaustive()
1344 assert_eq!(a.difference(b), a - b, "named != op: `{:?}` - `{:?}`", a, b,); in test_set_ops_exhaustive()
1345 // Note: Difference is checked as both `a - b` and `b - a` in test_set_ops_exhaustive()
1346 assert_eq!(b.difference(a), b - a, "named != op: `{:?}` - `{:?}`", b, a,); in test_set_ops_exhaustive()
1388 m1 -= m1; in test_assignment_operators()
1468 fn hash<T: Hash>(t: &T) -> u64 { in hash()
1491 assert_eq!(format!("{:?}", Flags::A | Flags::B), "A | B"); in test_debug()
1492 assert_eq!(format!("{:?}", Flags::empty()), "(empty)"); in test_debug()
1493 assert_eq!(format!("{:?}", Flags::ABC), "A | B | C | ABC"); in test_debug()
1494 let extra = unsafe { Flags::from_bits_unchecked(0xb8) }; in test_debug() localVariable
1495 assert_eq!(format!("{:?}", extra), "0xb8"); in test_debug()
1496 assert_eq!(format!("{:?}", Flags::A | extra), "A | 0xb8"); in test_debug()
1499 format!("{:?}", Flags::ABC | extra), in test_debug()
1503 assert_eq!(format!("{:?}", EmptyFlags::empty()), "(empty)"); in test_debug()
1508 assert_eq!(format!("{:b}", Flags::ABC), "111"); in test_binary()
1509 assert_eq!(format!("{:#b}", Flags::ABC), "0b111"); in test_binary()
1510 let extra = unsafe { Flags::from_bits_unchecked(0b1010000) }; in test_binary() localVariable
1511 assert_eq!(format!("{:b}", Flags::ABC | extra), "1010111"); in test_binary()
1512 assert_eq!(format!("{:#b}", Flags::ABC | extra), "0b1010111"); in test_binary()
1517 assert_eq!(format!("{:o}", LongFlags::LONG_A), "177777"); in test_octal()
1518 assert_eq!(format!("{:#o}", LongFlags::LONG_A), "0o177777"); in test_octal()
1519 let extra = unsafe { LongFlags::from_bits_unchecked(0o5000000) }; in test_octal() localVariable
1520 assert_eq!(format!("{:o}", LongFlags::LONG_A | extra), "5177777"); in test_octal()
1521 assert_eq!(format!("{:#o}", LongFlags::LONG_A | extra), "0o5177777"); in test_octal()
1526 assert_eq!(format!("{:x}", LongFlags::LONG_A), "ffff"); in test_lowerhex()
1527 assert_eq!(format!("{:#x}", LongFlags::LONG_A), "0xffff"); in test_lowerhex()
1528 let extra = unsafe { LongFlags::from_bits_unchecked(0xe00000) }; in test_lowerhex() localVariable
1529 assert_eq!(format!("{:x}", LongFlags::LONG_A | extra), "e0ffff"); in test_lowerhex()
1530 assert_eq!(format!("{:#x}", LongFlags::LONG_A | extra), "0xe0ffff"); in test_lowerhex()
1535 assert_eq!(format!("{:X}", LongFlags::LONG_A), "FFFF"); in test_upperhex()
1536 assert_eq!(format!("{:#X}", LongFlags::LONG_A), "0xFFFF"); in test_upperhex()
1537 let extra = unsafe { LongFlags::from_bits_unchecked(0xe00000) }; in test_upperhex() localVariable
1538 assert_eq!(format!("{:X}", LongFlags::LONG_A | extra), "E0FFFF"); in test_upperhex()
1539 assert_eq!(format!("{:#X}", LongFlags::LONG_A | extra), "0xE0FFFF"); in test_upperhex()
1591 assert_eq!(format!("{:?}", Flags::A), "A"); in test_in_function()
1633 pub(super) fn value() -> u8 { in test_pub_in_module()
1638 pub fn value() -> u8 { in test_pub_in_module()
1659 assert_eq!(format!("{:?}", Flags::empty()), "NONE"); in test_zero_value_flags()
1660 assert_eq!(format!("{:?}", Flags::SOME), "SOME"); in test_zero_value_flags()
1687 assert_eq!(format!("{:?}", Flags128::A), "A"); in test_u128_bitflags()
1688 assert_eq!(format!("{:?}", Flags128::B), "B"); in test_u128_bitflags()
1689 assert_eq!(format!("{:?}", Flags128::C), "C"); in test_u128_bitflags()
1690 assert_eq!(format!("{:?}", Flags128::ABC), "A | B | C | ABC"); in test_u128_bitflags()