Skip to content

Commit

Permalink
Rename variants to flags
Browse files Browse the repository at this point in the history
Rename:
- all_variants -> all_flags
- is_all_variants -> is_all_flags
  • Loading branch information
DCNick3 committed May 16, 2024
1 parent 4d89b28 commit b9b4858
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn main() {

println!("{:?}", BitmaskVecDebug::none()); // BitmaskVecDebug[]
println!("{:?}", BitmaskVecDebug::Flag1); // BitmaskVecDebug[Flag1]
println!("{:?}", BitmaskVecDebug::all_variants()); // BitmaskVecDebug[Flag1, Flag2]
println!("{:?}", BitmaskVecDebug::all_flags()); // BitmaskVecDebug[Flag1, Flag2]
}
```

Expand All @@ -138,14 +138,14 @@ const fn bits(&self) -> #type;
// Returns a bitmask that contains all values.
//
// This will include bits that do not have any flags.
// Use `::all_variants()` if you only want to use flags.
// This will include bits that do not have any associated flags.
// Use `::all_flags()` if you only want to use flags.
const fn all_bits() -> Self;
// Returns `true` if the bitmask contains all values.
//
// This will check for `bits == !0`,
// use `.is_all_variants()` if you only want to check for all flags
// use `.is_all_flags()` if you only want to check for all flags
const fn is_all_bits(&self) -> bool;
// Returns a bitmask that does not contain any values.
Expand All @@ -155,13 +155,13 @@ const fn none() -> Self;
const fn is_none(&self) -> bool;
// Returns a bitmask that contains all flags.
const fn all_variants() -> Self;
const fn all_flags() -> Self;
// Returns `true` if the bitmask contains all flags.
//
// This will fail if any unused bit is set,
// consider using `.truncate()` first.
const fn is_all_variants(&self) -> bool;
const fn is_all_flags(&self) -> bool;
// Returns a bitmask that only has bits corresponding to flags
const fn truncate(&self) -> Self;
Expand Down
24 changes: 12 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,22 @@ pub fn parse(attr: TokenStream, mut item: ItemEnum) -> Result<TokenStream> {
/// Returns a bitmask that contains all values.
///
/// This will include bits that do not have any flags.
/// Use `::all_variants()` if you only want to use flags.
/// Use `::all_flags()` if you only want to use flags.
#[inline]
#vis const fn all_bits() -> Self {
Self { bits: !0 }
}

/// Returns a bitmask that contains all flags.
#[inline]
#vis const fn all_variants() -> Self {
#vis const fn all_flags() -> Self {
Self { bits: #(#all_flags.bits |)* 0 }
}

/// Returns `true` if the bitmask contains all values.
///
/// This will check for `bits == !0`,
/// use `.is_all_variants()` if you only want to check for all flags
/// use `.is_all_flags()` if you only want to check for all flags
#[inline]
#vis const fn is_all_bits(&self) -> bool {
self.bits == !0
Expand All @@ -145,14 +145,14 @@ pub fn parse(attr: TokenStream, mut item: ItemEnum) -> Result<TokenStream> {
/// This will fail if any unused bit is set,
/// consider using `.truncate()` first.
#[inline]
#vis const fn is_all_variants(&self) -> bool {
self.bits == Self::all_variants().bits
#vis const fn is_all_flags(&self) -> bool {
self.bits == Self::all_flags().bits
}

/// Returns a bitmask that contains all values.
///
/// This will include bits that do not have any flags.
/// Use `::all_variants()` if you only want to use flags.
/// Use `::all_flags()` if you only want to use flags.
#[inline]
#[deprecated(note = "Please use the all_bits constructor")]
#vis const fn all() -> Self {
Expand All @@ -162,7 +162,7 @@ pub fn parse(attr: TokenStream, mut item: ItemEnum) -> Result<TokenStream> {
/// Returns `true` if the bitmask contains all values.
///
/// This will check for `bits == !0`,
/// use `.is_all_variants()` if you only want to check for all flags
/// use `.is_all_flags()` if you only want to check for all flags
#[inline]
#[deprecated(note = "Please use the is_all_bits method")]
#vis const fn is_all(&self) -> bool {
Expand All @@ -172,19 +172,19 @@ pub fn parse(attr: TokenStream, mut item: ItemEnum) -> Result<TokenStream> {

/// Returns a bitmask that contains all flags.
#[inline]
#[deprecated(note = "Please use the all_variants constructor")]
#[deprecated(note = "Please use the all_flags constructor")]
#vis const fn full() -> Self {
Self::all_variants()
Self::all_flags()
}

/// Returns `true` if the bitmask contains all flags.
///
/// This will fail if any unused bit is set,
/// consider using `.truncate()` first.
#[inline]
#[deprecated(note = "Please use the is_all_variants method")]
#[deprecated(note = "Please use the is_all_flags method")]
#vis const fn is_full(&self) -> bool {
self.is_all_variants()
self.is_all_flags()
}

/// Returns a bitmask that does not contain any values.
Expand All @@ -202,7 +202,7 @@ pub fn parse(attr: TokenStream, mut item: ItemEnum) -> Result<TokenStream> {
/// Returns a bitmask that only has bits corresponding to flags
#[inline]
#vis const fn truncate(&self) -> Self {
Self { bits: self.bits & Self::all_variants().bits }
Self { bits: self.bits & Self::all_flags().bits }
}

/// Returns `true` if `self` intersects with any value in `other`,
Expand Down
16 changes: 8 additions & 8 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ mod tests {

#[test]

fn test_all_variants() {
let all_variants = Bitmask::all_variants();
assert_eq!(all_variants.is_all_variants(), true);
fn test_all_flags() {
let all_flags = Bitmask::all_flags();
assert_eq!(all_flags.is_all_flags(), true);
assert_eq!(
all_variants,
all_flags,
Bitmask::Flag1
| Bitmask::Flag2
| Bitmask::Flag3
Expand All @@ -74,8 +74,8 @@ mod tests {
fn test_truncate() {
let all = Bitmask::all_bits();
assert_eq!(all.is_all_bits(), true);
assert_eq!(all.is_all_variants(), false);
assert_eq!(all.truncate().is_all_variants(), true);
assert_eq!(all.is_all_flags(), false);
assert_eq!(all.truncate().is_all_flags(), true);
}

#[test]
Expand Down Expand Up @@ -383,7 +383,7 @@ mod tests {
"BitmaskVecDebug[Flag2, Flag3]"
);
assert_eq!(
format!("{:?}", BitmaskVecDebug::all_variants()),
format!("{:?}", BitmaskVecDebug::all_flags()),
"BitmaskVecDebug[Flag1, Flag2, Flag12, Flag3]"
);

Expand Down Expand Up @@ -428,7 +428,7 @@ mod tests {
"BitmaskVecDebug[Flag1, InvertedFlag2]"
);
assert_eq!(
format!("{:?}", BitmaskVecDebug::all_variants()),
format!("{:?}", BitmaskVecDebug::all_flags()),
"BitmaskVecDebug[Flag1, InvertedFlag1, Flag2, InvertedFlag2]"
);
}
Expand Down

0 comments on commit b9b4858

Please sign in to comment.