Skip to content

Commit

Permalink
Merge pull request #27 from Freax13/enhancement/tracker-caller
Browse files Browse the repository at this point in the history
add `#[track_caller]` to methods
  • Loading branch information
phil-opp authored Feb 25, 2023
2 parents a077a34 + 9f6d278 commit 144c718
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ macro_rules! bitfield_numeric_impl {
impl BitField for $t {
const BIT_LENGTH: usize = ::core::mem::size_of::<Self>() as usize * 8;

#[track_caller]
#[inline]
fn get_bit(&self, bit: usize) -> bool {
assert!(bit < Self::BIT_LENGTH);

(*self & (1 << bit)) != 0
}

#[track_caller]
#[inline]
fn get_bits<T: RangeBounds<usize>>(&self, range: T) -> Self {
let range = to_regular_range(&range, Self::BIT_LENGTH);
Expand All @@ -233,6 +235,7 @@ macro_rules! bitfield_numeric_impl {
bits >> range.start
}

#[track_caller]
#[inline]
fn set_bit(&mut self, bit: usize, value: bool) -> &mut Self {
assert!(bit < Self::BIT_LENGTH);
Expand All @@ -246,6 +249,7 @@ macro_rules! bitfield_numeric_impl {
self
}

#[track_caller]
#[inline]
fn set_bits<T: RangeBounds<usize>>(&mut self, range: T, value: Self) -> &mut Self {
let range = to_regular_range(&range, Self::BIT_LENGTH);
Expand Down Expand Up @@ -278,13 +282,15 @@ impl<T: BitField> BitArray<T> for [T] {
self.len() * T::BIT_LENGTH
}

#[track_caller]
#[inline]
fn get_bit(&self, bit: usize) -> bool {
let slice_index = bit / T::BIT_LENGTH;
let bit_index = bit % T::BIT_LENGTH;
self[slice_index].get_bit(bit_index)
}

#[track_caller]
#[inline]
fn get_bits<U: RangeBounds<usize>>(&self, range: U) -> T {
let range = to_regular_range(&range, self.bit_length());
Expand Down Expand Up @@ -313,13 +319,15 @@ impl<T: BitField> BitArray<T> for [T] {
}
}

#[track_caller]
#[inline]
fn set_bit(&mut self, bit: usize, value: bool) {
let slice_index = bit / T::BIT_LENGTH;
let bit_index = bit % T::BIT_LENGTH;
self[slice_index].set_bit(bit_index, value);
}

#[track_caller]
#[inline]
fn set_bits<U: RangeBounds<usize>>(&mut self, range: U, value: T) {
let range = to_regular_range(&range, self.bit_length());
Expand Down

0 comments on commit 144c718

Please sign in to comment.