pub struct Bitfield {
pub pages: Pager,
/* private fields */
}
Expand description
Bitfield instance.
Fields§
§pages: Pager
A memory-pager instance.
Implementations§
Source§impl Bitfield
impl Bitfield
Sourcepub fn from_file(
file: &mut File,
page_size: usize,
offset: Option<usize>,
) -> Result<Self>
pub fn from_file( file: &mut File, page_size: usize, offset: Option<usize>, ) -> Result<Self>
Create a new instance from a File
.
Sourcepub fn set(&mut self, index: usize, value: bool) -> Change
pub fn set(&mut self, index: usize, value: bool) -> Change
Set a bit to true or false. Returns a boolean indicating if the value was changed.
Sourcepub fn set_byte(&mut self, index: usize, byte: u8) -> Change
pub fn set_byte(&mut self, index: usize, byte: u8) -> Change
Set a byte to the right value inside our internal buffers.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the amount of bits in the bitfield.
§Examples
let mut bits = Bitfield::new(1024);
assert_eq!(bits.len(), 0);
bits.set(0, true);
assert_eq!(bits.len(), 8);
bits.set(1, true);
assert_eq!(bits.len(), 8);
bits.set(9, false);
assert_eq!(bits.len(), 16);
Sourcepub fn byte_len(&self) -> usize
pub fn byte_len(&self) -> usize
Get the amount of bytes in the bitfield.
§Examples
let mut bits = Bitfield::new(1024);
assert_eq!(bits.byte_len(), 0);
bits.set(0, true);
assert_eq!(bits.byte_len(), 1);
bits.set(1, true);
assert_eq!(bits.byte_len(), 1);
bits.set(9, false);
assert_eq!(bits.byte_len(), 2);
Sourcepub fn page_len(&self) -> usize
pub fn page_len(&self) -> usize
Get the amount of memory pages in the bitfield.
§Examples
let mut bits = Bitfield::new(1024);
assert_eq!(bits.page_len(), 0);
bits.set(0, true);
assert_eq!(bits.page_len(), 1);
bits.set(1, true);
assert_eq!(bits.page_len(), 1);
bits.set(2, false);
assert_eq!(bits.page_len(), 1);
bits.set(1024 * 8 + 1, true);
assert_eq!(bits.page_len(), 2);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bitfield
impl RefUnwindSafe for Bitfield
impl Send for Bitfield
impl Sync for Bitfield
impl Unpin for Bitfield
impl UnwindSafe for Bitfield
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more