Skip to main content

Mask

Struct Mask 

Source
pub struct Mask<const N: usize, T, A: Alignment>(/* private fields */)
where
    Length<N>: SupportedLength,
    T: Scalar;
Expand description

A generic vector mask.

Mask is the generic form of:

Mask is generic over:

  • N: Length (2, 3, or 4)
  • T: Scalar type (see Scalar)
  • A: Alignment (see Alignment)

To initialize masks, use the functions Mask2::new, Mask3::new, Mask4::new. To initialize a mask of an unknown length, use Mask::from_array.

§Guarantees

Mask<N, T, A> doesn’t have a stable representation, but does guarantee certain properties.

Mask<N, T, A> bytes are initialized and zeroable.

Masks of scalar types with the same Scalar::Repr are guaranteed to have compatible memory layouts, even if Repr = (). They are guaranteed to have the same size, element positions, and alignment.

Types containing compatible Mask types are not guaranteed to have the same memory layout. For example, even though Mask2<bool> and Mask2<u8> have the same memory layout, Option<Mask2<bool>> and Option<Mask2<u8>> may not.

Implementations§

Source§

impl<const N: usize, T, A: Alignment> Mask<N, T, A>

Source

pub fn from_array(array: [bool; N]) -> Self

Creates a mask from an array.

The preferable way to create masks is using the functions Mask2::new, Mask3::new, Mask4::new.

Mask::from_array should only be used when the length of the mask is unknown or when directly converting from an array.

Source

pub fn splat(value: bool) -> Self

Creates a mask with all components set to the given value.

Source

pub fn from_fn<F>(f: F) -> Self
where F: FnMut(usize) -> bool,

Creates a mask by calling function f for each component index.

Equivalent to (f(0), f(1), f(2), ...).

Source

pub fn to_alignment<A2: Alignment>(self) -> Mask<N, T, A2>

Converts the mask to the specified alignment.

See Alignment for more information.

Source

pub fn align(self) -> Mask<N, T, Aligned>

Converts the mask to Aligned alignment.

See Alignment for more information.

Source

pub fn unalign(self) -> Mask<N, T, Unaligned>

Converts the mask to Unaligned alignment.

See Alignment for more information.

Source

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

Converts the mask to an array.

Source

pub fn all(self) -> bool

Returns true if all of the mask’s components are true.

Source

pub fn any(self) -> bool

Returns true if any of the mask’s components are true.

Source

pub fn select( self, if_true: Vector<N, T, A>, if_false: Vector<N, T, A>, ) -> Vector<N, T, A>

Selects between the components of if_true and if_false based on the values of the mask.

Source

pub fn iter(self) -> IntoIter<bool, N>

Returns an iterator over the mask’s components.

Source

pub fn get(self, index: usize) -> bool

Returns the component at the given index.

§Panics

Panics if the index is out of bounds.

Source

pub fn set(&mut self, index: usize, value: bool)

Sets the component at the given index.

§Panics

Panics if the index is out of bounds.

Source

pub const fn to_repr<T2>(self) -> Mask<N, T2, A>
where T2: Scalar<Repr = T::Repr>,

Reinterprets the bits of the mask to a different scalar type.

The two scalar types must have compatible memory layouts. This is enforced via trait bounds in this function’s signature.

This function is used to make SIMD optimizations in implementations of Scalar.

Source§

impl<T, A: Alignment> Mask<2, T, A>
where T: Scalar,

Source

pub fn new(x: bool, y: bool) -> Self

Creates a 2-component mask.

Source§

impl<T, A: Alignment> Mask<3, T, A>
where T: Scalar,

Source

pub fn new(x: bool, y: bool, z: bool) -> Self

Creates a 3-component mask.

Source§

impl<T, A: Alignment> Mask<4, T, A>
where T: Scalar,

Source

pub fn new(x: bool, y: bool, z: bool, w: bool) -> Self

Creates a 4-component mask.

Trait Implementations§

Source§

impl<const N: usize, T, A: Alignment> BitAnd<bool> for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitAnd for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitAndAssign<bool> for Mask<N, T, A>

Source§

fn bitand_assign(&mut self, rhs: bool)

Performs the &= operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitAndAssign for Mask<N, T, A>

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitOr<bool> for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitOr for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitOrAssign<bool> for Mask<N, T, A>

Source§

fn bitor_assign(&mut self, rhs: bool)

Performs the |= operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitOrAssign for Mask<N, T, A>

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitXor<bool> for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: bool) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitXor for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitXorAssign<bool> for Mask<N, T, A>

Source§

fn bitxor_assign(&mut self, rhs: bool)

Performs the ^= operation. Read more
Source§

impl<const N: usize, T, A: Alignment> BitXorAssign for Mask<N, T, A>

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<const N: usize, T, A: Alignment> Clone for Mask<N, T, A>

Source§

fn clone(&self) -> Self

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<const N: usize, T, A: Alignment> Debug for Mask<N, T, A>

Source§

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

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

impl<const N: usize, T, A: Alignment> Default for Mask<N, T, A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize, T, A: Alignment> Display for Mask<N, T, A>

Source§

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

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

impl<const N: usize, T, A: Alignment> Hash for Mask<N, T, A>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize, T, A: Alignment> IntoIterator for &Mask<N, T, A>

Source§

type Item = bool

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<bool, N>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const N: usize, T, A: Alignment> IntoIterator for Mask<N, T, A>

Source§

type Item = bool

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<bool, N>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const N: usize, T, A: Alignment> Not for Mask<N, T, A>

Source§

type Output = Mask<N, T, A>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<const N: usize, T, A: Alignment> PartialEq for Mask<N, T, A>

Source§

fn eq(&self, other: &Self) -> 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<const N: usize, T, A: Alignment> Copy for Mask<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Eq for Mask<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> RefUnwindSafe for Mask<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Send for Mask<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Sync for Mask<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> Unpin for Mask<N, T, A>

Source§

impl<const N: usize, T, A: Alignment> UnwindSafe for Mask<N, T, A>

Auto Trait Implementations§

§

impl<const N: usize, T, A> Freeze for Mask<N, T, A>
where <<T as Scalar>::Repr as ScalarRepr>::MaskRepr<N, A>: Freeze,

§

impl<const N: usize, T, A> UnsafeUnpin for Mask<N, T, A>
where <<T as Scalar>::Repr as ScalarRepr>::MaskRepr<N, A>: UnsafeUnpin,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.