use super::Bits;
use adapter::*;
pub trait BitsExt: Bits {
fn bit_concat<Other>(&self, other: Other) -> BitConcat<&Self, Other>
where Other: Bits<Block = Self::Block> {
BitConcat::new(self, other)
}
fn into_bit_concat<Other>(self, other: Other) -> BitConcat<Self, Other>
where Self: Sized,
Other: Bits<Block = Self::Block> {
BitConcat::new(self, other)
}
fn bit_pad(&self, len: u64) -> BitConcat<&Self, BitFill<Self::Block>> {
self.into_bit_pad(len)
}
fn into_bit_pad(self, len: u64) -> BitConcat<Self, BitFill<Self::Block>>
where Self: Sized {
let have = self.bit_len();
let need = if len > have {len - have} else {0};
self.into_bit_concat(BitFill::zeroes(need))
}
fn bit_not(&self) -> BitNot<&Self> {
BitNot::new(self)
}
fn into_bit_not(self) -> BitNot<Self>
where Self: Sized
{
BitNot::new(self)
}
fn bit_and<Other>(&self, other: Other) -> BitAnd<&Self, Other>
where Other: Bits<Block = Self::Block> {
BitAnd::new(self, other)
}
fn into_bit_and<Other>(self, other: Other) -> BitAnd<Self, Other>
where Self: Sized,
Other: Bits<Block = Self::Block> {
BitAnd::new(self, other)
}
fn bit_or<Other>(&self, other: Other) -> BitOr<&Self, Other>
where Other: Bits<Block = Self::Block> {
BitOr::new(self, other)
}
fn into_bit_or<Other>(self, other: Other) -> BitOr<Self, Other>
where Self: Sized,
Other: Bits<Block = Self::Block> {
BitOr::new(self, other)
}
fn bit_xor<Other>(&self, other: Other) -> BitXor<&Self, Other>
where Other: Bits<Block = Self::Block> {
BitXor::new(self, other)
}
fn into_bit_xor<Other>(self, other: Other) -> BitXor<Self, Other>
where Self: Sized,
Other: Bits<Block = Self::Block> {
BitXor::new(self, other)
}
fn bit_zip<Other, F>(&self, other: Other, fun: F) -> BitZip<&Self, Other, F>
where Other: Bits<Block = Self::Block>,
F: Fn(Self::Block, Self::Block, usize) -> Self::Block {
BitZip::new(self, other, fun)
}
fn into_bit_zip<Other, F>(self, other: Other, fun: F) -> BitZip<Self, Other, F>
where Self: Sized,
Other: Bits<Block = Self::Block>,
F: Fn(Self::Block, Self::Block, usize) -> Self::Block {
BitZip::new(self, other, fun)
}
}
impl<T: Bits> BitsExt for T {}