pub trait BitvectorExtended: Sized {
// Required methods
fn into_resize_unsigned(self, size: ByteSize) -> Self;
fn into_resize_signed(self, size: ByteSize) -> Self;
fn cast(&self, kind: CastOpType, width: ByteSize) -> Result<Self, Error>;
fn subpiece(&self, low_byte: ByteSize, size: ByteSize) -> Self;
fn un_op(&self, op: UnOpType) -> Result<Self, Error>;
fn bin_op(&self, op: BinOpType, rhs: &Self) -> Result<Self, Error>;
fn signed_add_overflow_checked(&self, rhs: &Self) -> Option<Self>;
fn signed_sub_overflow_checked(&self, rhs: &Self) -> Option<Self>;
fn signed_mult_with_overflow_flag(
&self,
rhs: &Self
) -> Result<(Self, bool), Error>;
fn bytesize(&self) -> ByteSize;
}
Expand description
A trait to extend the bitvector type with useful helper functions
that are not contained in the apint
crate.
Required Methods§
sourcefn into_resize_unsigned(self, size: ByteSize) -> Self
fn into_resize_unsigned(self, size: ByteSize) -> Self
Resize self
to the target byte size by either zero extending or truncating self
.
sourcefn into_resize_signed(self, size: ByteSize) -> Self
fn into_resize_signed(self, size: ByteSize) -> Self
Resize self
to the target byte size by either sign extending or truncating self
.
sourcefn cast(&self, kind: CastOpType, width: ByteSize) -> Result<Self, Error>
fn cast(&self, kind: CastOpType, width: ByteSize) -> Result<Self, Error>
Perform a cast operation on the bitvector. Returns an error for non-implemented cast operations (currently all float-related casts).
sourcefn subpiece(&self, low_byte: ByteSize, size: ByteSize) -> Self
fn subpiece(&self, low_byte: ByteSize, size: ByteSize) -> Self
Extract a subpiece from the given bitvector.
sourcefn un_op(&self, op: UnOpType) -> Result<Self, Error>
fn un_op(&self, op: UnOpType) -> Result<Self, Error>
Perform a unary operation on the given bitvector. Returns an error for non-implemented operations (currently all float-related operations).
sourcefn bin_op(&self, op: BinOpType, rhs: &Self) -> Result<Self, Error>
fn bin_op(&self, op: BinOpType, rhs: &Self) -> Result<Self, Error>
Perform a binary operation on the given bitvectors. Returns an error for non-implemented operations (currently all float-related operations).
sourcefn signed_add_overflow_checked(&self, rhs: &Self) -> Option<Self>
fn signed_add_overflow_checked(&self, rhs: &Self) -> Option<Self>
Returns the result of self + rhs
if the computation does not result in a signed integer overflow or underflow.
sourcefn signed_sub_overflow_checked(&self, rhs: &Self) -> Option<Self>
fn signed_sub_overflow_checked(&self, rhs: &Self) -> Option<Self>
Returns the result of self - rhs
if the computation does not result in a signed integer overflow or underflow.
sourcefn signed_mult_with_overflow_flag(
&self,
rhs: &Self
) -> Result<(Self, bool), Error>
fn signed_mult_with_overflow_flag( &self, rhs: &Self ) -> Result<(Self, bool), Error>
Return the result of multiplying self
with rhs
and a flag that is set to true
if the multiplication resulted in a signed integer overflow or underflow.
Returns an error for bitvectors larger than 8 bytes,
since multiplication for them is not yet implemented in the apint
crate.