Trait UnsetBit

Source
pub trait UnsetBit {
    // Required method
    fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
       where Self: Sized;
}
Expand description

performing _ & !(1 << idx) with n the index

§Examples

§unset bit for big int

Don’t pay attention to my bigint implementation.

pub struct BigInt {
	hwb: i64,
	lwb: i64,
}
impl UnsetBit for BigInt {
	fn unset_bit(&self, idx: usize) -> Result<Self,IndexError> where Self: Sized {
		if idx >= 128 {
			Err(IndexError)
		} else if idx >= 64 {
			Ok(BigInt{
				hwb: self.hwb & !(1 << (idx - 64)),
				lwb: self.lwb
			})
		} else {
			Ok(BigInt{
				hwb: self.hwb,
				lwb: self.lwb & !(1 << (idx - 64))
			})
		}
	}
}

Required Methods§

Source

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Implementations on Foreign Types§

Source§

impl UnsetBit for i8

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for i16

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for i32

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for i64

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for isize

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for u8

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for u16

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for u32

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for u64

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Source§

impl UnsetBit for usize

Source§

fn unset_bit(&self, idx: usize) -> Result<Self, IndexError>
where Self: Sized,

Implementors§