Trait ArrayBinary

Source
pub trait ArrayBinary<N: Numeric>
where Self: Sized + Clone,
{ // Required methods fn bitwise_and(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>; fn bitwise_or(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>; fn bitwise_xor(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>; fn bitwise_not(&self) -> Result<Array<N>, ArrayError>; fn invert(&self) -> Result<Array<N>, ArrayError>; fn left_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>; fn right_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>; fn binary_repr(num: N) -> String; }
Expand description

ArrayTrait - Binary Array operations

Required Methods§

Source

fn bitwise_and(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Compute the bit-wise AND of two arrays element-wise

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<i32>::flat(vec![1]), array!(i32, [13]).bitwise_and(&array!(i32, [17]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![0, 1]), array!(i32, [11, 7]).bitwise_and(&array!(i32, [4, 25]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![2, 4, 16]), array!(i32, [2, 5, 255]).bitwise_and(&array!(i32, [3, 14, 16]).unwrap()));
§Errors

may returns ArrayError

Source

fn bitwise_or(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Compute the bit-wise OR of two arrays element-wise

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<i32>::flat(vec![29]), array!(i32, [13]).bitwise_or(&array!(i32, [16]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![33, 6]), array!(i32, [33, 4]).bitwise_or(&array!(i32, [1, 2]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![6, 5, 255]), array!(i32, [2, 5, 255]).bitwise_or(&array!(i32, [4, 4, 4]).unwrap()));
§Errors

may returns ArrayError

Source

fn bitwise_xor(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Compute the bit-wise XOR of two arrays element-wise

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<i32>::flat(vec![28]), array!(i32, [13]).bitwise_xor(&array!(i32, [17]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![26]), array!(i32, [31]).bitwise_xor(&array!(i32, [5]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![26, 5]), array!(i32, [31, 3]).bitwise_xor(&array!(i32, [5, 6]).unwrap()));
§Errors

may returns ArrayError

Source

fn bitwise_not(&self) -> Result<Array<N>, ArrayError>

Compute bit-wise inversion, or bit-wise NOT, element-wise

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![242]), array!(u8, [13]).bitwise_not());
assert_eq!(Array::<u16>::flat(vec![65522]), array!(u16, [13]).bitwise_not());
assert_eq!(Array::<i32>::flat(vec![-14]), array!(i32, [13]).bitwise_not());
§Errors

may returns ArrayError

Source

fn invert(&self) -> Result<Array<N>, ArrayError>

Compute bit-wise inversion, or bit-wise NOT, element-wise. Alias on bitwise_not

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![242]), array!(u8, [13]).invert());
assert_eq!(Array::<u16>::flat(vec![65522]), array!(u16, [13]).invert());
assert_eq!(Array::<i32>::flat(vec![-14]), array!(i32, [13]).invert());
§Errors

may returns ArrayError

Source

fn left_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Shift the bits of an integer to the left

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![20]), array!(u8, [5]).left_shift(&array!(u8, [2]).unwrap()));
assert_eq!(Array::<u8>::flat(vec![10, 20, 40]), array!(u8, [5]).left_shift(&array!(u8, [1, 2, 3]).unwrap()));
§Errors

may returns ArrayError

Source

fn right_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Shift the bits of an integer to the right

§Arguments
  • other - array to perform the operation with
§Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![5]), array!(u8, [10]).right_shift(&array!(u8, [1]).unwrap()));
assert_eq!(Array::<u8>::flat(vec![5, 2, 1]), array!(u8, [10]).right_shift(&array!(u8, [1, 2, 3]).unwrap()));
§Errors

may returns ArrayError

Source

fn binary_repr(num: N) -> String

Return the binary representation of the input number as a string

§Arguments
  • num - integer decimal number
§Examples
use arr_rs::prelude::*;

assert_eq!("10".to_string(), 2u8.binary_repr());
assert_eq!("11".to_string(), 3u8.binary_repr());
assert_eq!("11111101".to_string(), (-3i8).binary_repr());
assert_eq!("11111111".to_string(), 255u8.binary_repr());

assert_eq!("10".to_string(), Array::<u8>::binary_repr(2));
assert_eq!("11".to_string(), Array::<u8>::binary_repr(3));
assert_eq!("11111101".to_string(), Array::<i8>::binary_repr(-3));
assert_eq!("11111111".to_string(), Array::<u8>::binary_repr(255));
§Errors

may returns ArrayError

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<N: Numeric> ArrayBinary<N> for Result<Array<N>, ArrayError>

Source§

fn bitwise_and(&self, other: &Array<N>) -> Self

Source§

fn bitwise_or(&self, other: &Array<N>) -> Self

Source§

fn bitwise_xor(&self, other: &Array<N>) -> Self

Source§

fn bitwise_not(&self) -> Self

Source§

fn invert(&self) -> Self

Source§

fn left_shift(&self, other: &Array<N>) -> Self

Source§

fn right_shift(&self, other: &Array<N>) -> Self

Source§

fn binary_repr(num: N) -> String

Implementors§

Source§

impl<N: Numeric> ArrayBinary<N> for Array<N>