Trait polyvalue::operations::BitwiseOperationExt
source · pub trait BitwiseOperationExt {
// Required methods
fn bitwise_op(
left: &Self,
right: &Self,
operation: BitwiseOperation
) -> Result<Self, Error>
where Self: Sized;
fn bitwise_not(&self) -> Result<Self, Error>
where Self: Sized;
}Expand description
Trait for bitwise operations
Required Methods§
sourcefn bitwise_op(
left: &Self,
right: &Self,
operation: BitwiseOperation
) -> Result<Self, Error>where
Self: Sized,
fn bitwise_op(
left: &Self,
right: &Self,
operation: BitwiseOperation
) -> Result<Self, Error>where
Self: Sized,
Perform a bitwise operation on two values
If the operation is not supported on the given type,
an Error::UnsupportedOperation will be returned
Examples
use polyvalue::{Value};
use polyvalue::operations::{BitwiseOperation, BitwiseOperationExt};
let a = Value::from(0x0F);
let b = Value::from(0xF0);
let result = Value::bitwise_op(&a, &b, BitwiseOperation::And).unwrap();
assert_eq!(result, Value::from(0x00));sourcefn bitwise_not(&self) -> Result<Self, Error>where
Self: Sized,
fn bitwise_not(&self) -> Result<Self, Error>where
Self: Sized,
Perform a bitwise not on a value
This is equivalent to bitwise_op with BitwiseOperation::Not
but is provided for convenience
Please note that a mask is applied to the result of this operation in order to ensure that the result is the same size as the input and correct for the way the underlying data is stored
Examples
use polyvalue::{Value};
use polyvalue::operations::{BitwiseOperation, BitwiseOperationExt};
let a = Value::from(0xA0);
let result = a.bitwise_not().unwrap();
assert_eq!(result, Value::from(0x5F));