Struct BitArray

Source
pub struct BitArray {
    pub size: i64,
    pub bit_array: Vec<u8>,
}
Expand description

A structure aimed to bring the bitarray functionality. Structure is described within two fields. “size” - The number of bits that will be allocated during the struct instance initialization. “bit_array” - The vector of 8 bit integer used to represent bits where each 8 bits are packed in every 8 bit integer.

use bitarray_naive::BitArray;

let bitarray_size: i64 = 9999;

let mut bitarray: BitArray = BitArray::new(bitarray_size);

bitarray.set(12, true).unwrap();

assert_eq!(bitarray.get(12).unwrap(), true);

Fields§

§size: i64§bit_array: Vec<u8>

Implementations§

Source§

impl BitArray

Source

pub fn new(size: i64) -> Self

Constructor used to initialize a new instance of the bitarray with a given size. “size” - The number of bits that will be allocated during the struct instance initialization.

Source

pub fn set(&mut self, position: i64, flag: bool) -> Result<(), OutOfRangeError>

Sets either true or false value in bit array at given position.

Source

pub fn get(&self, position: i64) -> Result<bool, OutOfRangeError>

Gets either true or false value in bit array at given position.

Trait Implementations§

Source§

impl Debug for BitArray

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BitArray

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for BitArray

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,