Skip to content

Commit

Permalink
[feat] add two constructor, from_raw_bits and one_shot
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Sep 27, 2024
1 parent b4eab5e commit 0337f97
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ where
}
}

/// Construct a cpumask from a `usize` value.
/// Construct a cpumask from a raw `usize` value.
/// The value must be less than `2^SIZE`, panick if the value is too large.
pub fn from_usize(value: usize) -> Self {
pub fn from_raw_bits(value: usize) -> Self {
assert!(value >> SIZE == 0);

let mut bit_map = Bitmap::new();
Expand All @@ -127,6 +127,12 @@ where
Self { value: bit_map }
}

pub fn one_shot(index: usize) -> Self {
let mut bit_map = Bitmap::new();
bit_map.set(index, true);
Self { value: bit_map }
}

/// Convert this cpumask into a value of the type of its backing store.
#[inline]
pub fn into_value(self) -> <BitsImpl<SIZE> as Bits>::Store {
Expand Down

0 comments on commit 0337f97

Please sign in to comment.