Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change set_aliased to return the previous bit value #273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ where
O: BitOrder,
{
/// Writes a new value into a single bit, using alias-safe operations.
/// Returns the previous value of the bit.
///
/// This is equivalent to [`.set()`], except that it does not require an
/// `&mut` reference, and allows bit-slices with alias-safe storage to share
Expand Down Expand Up @@ -1687,15 +1688,15 @@ where
///
/// [`.set()`]: Self::set
#[inline]
pub fn set_aliased(&self, index: usize, value: bool) {
pub fn set_aliased(&self, index: usize, value: bool) -> bool {
self.assert_in_bounds(index, 0 .. self.len());
unsafe {
self.set_aliased_unchecked(index, value);
self.set_aliased_unchecked(index, value)
}
}

/// Writes a new value into a single bit, using alias-safe operations and
/// without bounds checking.
/// without bounds checking. Returns the previous value of the bit.
///
/// This is equivalent to [`.set_unchecked()`], except that it does not
/// require an `&mut` reference, and allows bit-slices with alias-safe
Expand Down Expand Up @@ -1728,8 +1729,8 @@ where
///
/// [`.set_unchecked()`]: Self::set_unchecked
#[inline]
pub unsafe fn set_aliased_unchecked(&self, index: usize, value: bool) {
self.as_bitptr().add(index).freeze().frozen_write_bit(value);
pub unsafe fn set_aliased_unchecked(&self, index: usize, value: bool) -> bool {
self.as_bitptr().add(index).freeze().frozen_write_bit(value)
}
}

Expand Down