mask8x8

Struct mask8x8 

Source
pub struct mask8x8 { /* private fields */ }
Expand description

A vector of eight bool values, which can have SIMD-like operations applied to them without any explicit SIMD instructions.

This type is really just a u64, but its methods interpret it as eight bool values where the same operation is applied to all eight values at once.

Implementations§

Source§

impl mask8x8

Source

pub const ALL_FALSE: Self

A mask8x8 value where all eight elements are set to false.

Source

pub const ALL_TRUE: Self

A mask8x8 value where all eight elements are set to true.

Source

pub const fn from_array(a: [bool; 8]) -> Self

Converts the given array into a mask8x8.

Source

pub const fn from_bitmask_le(mask: u8) -> Self

Converts the given bitmask into a mask8x8 by treating a set bit as true and an unset bit as false. The least significant bit appears in the first element.

let mask = mask8x8::from_bitmask_le(0b11001010);
assert_eq!(mask.to_array(), [false, true, false, true, false, false, true, true]);
Source

pub const fn from_bitmask_be(mask: u8) -> Self

Converts the given bitmask into a mask8x8 by treating a set bit as true and an unset bit as false. The least significant bit appears in the last element.

let mask = mask8x8::from_bitmask_be(0b11001010);
assert_eq!(mask.to_array(), [true, true, false, false, true, false, true, false]);
Source

pub const fn to_array(self) -> [bool; 8]

Converts the vector into an array of eight bool values.

Source

pub const fn to_bitmask_le(self) -> u8

Converts the vector into a bitmask where the first element is in the least significant bit.

Source

pub const fn to_bitmask_be(self) -> u8

Converts the vector into a bitmask where the first element is in the most significant bit.

Source

pub const fn to_u8x8(self) -> u8x8

Returns a u8x8 representation of the mask where true elements are represented as 0x01 and false elements are represented as 0x00.

Source

pub const fn to_u8x8_with(self, v: u8) -> u8x8

Returns a u8x8 representation of the mask where true elements are represented as v and false elements are represented as 0x00.

Source

pub const fn not(self) -> Self

Computes the complement of each element in the vector.

Source

pub const fn or(self, other: Self) -> Self

Computes a logical OR result for each element across both vectors.

Source

pub const fn and(self, other: Self) -> Self

Computes a logical AND result for each element across both vectors.

Source

pub const fn select(self, true_value: u8, false_value: u8) -> u8x8

Builds a u8x8 by selecting one of the two given values for each element corresponding to the elements in the mask.

For example, this can be useful when expanding a one-bit-per-pixel bitmap into eight palette indices represented as u8, as part of rendering an indexed-color pixmap:

let bitmap = 0b10101100;
let mask = mask8x8::from_bitmask_be(bitmap);
let fg_color = 0xff;
let bg_color = 0x01;
let pixels = mask.select(fg_color, bg_color);
assert_eq!(pixels.to_array(), [0xff, 0x01, 0xff, 0x01, 0xff, 0xff, 0x01, 0x01]);
Source

pub const fn count_true(self) -> u32

Returns the number of elements in the mask that are set to true.

Source

pub const fn count_false(self) -> u32

Returns the number of elements in the mask that are set to false.

Trait Implementations§

Source§

impl BitAnd for mask8x8

Source§

fn bitand(self, rhs: Self) -> Self

Implements the & operator using Self::and.

Source§

type Output = mask8x8

The resulting type after applying the & operator.
Source§

impl BitAndAssign for mask8x8

Source§

fn bitand_assign(&mut self, rhs: Self)

Implements the &= operator using Self::and.

Source§

impl BitOr for mask8x8

Source§

fn bitor(self, rhs: Self) -> Self

Implements the | operator using Self::or.

Source§

type Output = mask8x8

The resulting type after applying the | operator.
Source§

impl BitOrAssign for mask8x8

Source§

fn bitor_assign(&mut self, rhs: Self)

Implements the |= operator using Self::or.

Source§

impl Clone for mask8x8

Source§

fn clone(&self) -> mask8x8

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for mask8x8

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Not for mask8x8

Source§

fn not(self) -> Self

Implements the unary ! operator using Self::not.

Source§

type Output = mask8x8

The resulting type after applying the ! operator.
Source§

impl PartialEq for mask8x8

Source§

fn eq(&self, other: &mask8x8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for mask8x8

Source§

impl Eq for mask8x8

Source§

impl StructuralPartialEq for mask8x8

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.