Skip to main content

MaskAware

Trait MaskAware 

Source
pub trait MaskAware<T: Element, D: Dimension> {
    // Required methods
    fn data(&self) -> &Array<T, D>;
    fn mask_opt(&self) -> Option<&Array<bool, D>>;
    fn fill_value(&self) -> T
       where T: Copy;

    // Provided method
    fn shape(&self) -> &[usize] { ... }
}
Expand description

Shared view contract for functions that want to accept either an Array or a MaskedArray (#505).

Implementations:

  • Array<T, D>: data() returns self, mask_opt() returns None (no mask), fill_value() returns T::zero(). The array is treated as fully unmasked.
  • MaskedArray<T, D>: delegates to the existing accessors.

Downstream code that wants to write “one function, works on both” should take &impl MaskAware<T, D> and consult mask_opt() to decide whether to do mask propagation.

Required Methods§

Source

fn data(&self) -> &Array<T, D>

Return a reference to the underlying data array.

Source

fn mask_opt(&self) -> Option<&Array<bool, D>>

Return the mask array if one is explicitly present, or None when the input carries no mask (treated as fully unmasked).

For Array<T, D> this always returns None. For MaskedArray<T, D> it returns Some when a real mask has been explicitly set and None when the array is in the nomask-sentinel state (#506).

Source

fn fill_value(&self) -> T
where T: Copy,

Return the fill value to use for masked positions in derived results.

Provided Methods§

Source

fn shape(&self) -> &[usize]

Return the shape of the underlying data.

Implementations on Foreign Types§

Source§

impl<T: Element, D: Dimension> MaskAware<T, D> for Array<T, D>

Source§

fn mask_opt(&self) -> Option<&Array<bool, D>>

A plain Array<T, D> has no mask — always returns None.

Source§

fn fill_value(&self) -> T
where T: Copy,

A plain Array<T, D> has no fill value; returns T::zero().

Source§

fn data(&self) -> &Self

Implementors§

Source§

impl<T: Element, D: Dimension> MaskAware<T, D> for MaskedArray<T, D>