Type Definition ndarray::CowArray

source ·
pub type CowArray<'a, A, D> = ArrayBase<CowRepr<'a, A>, D>;
Expand description

An array with copy-on-write behavior.

An CowArray represents either a uniquely owned array or a view of an array. The 'a corresponds to the lifetime of the view variant.

This type is analogous to std::borrow::Cow. If a CowArray instance is the immutable view variant, then calling a method for mutating elements in the array will cause it to be converted into the owned variant (by cloning all the elements) before the modification is performed.

Array views have all the methods of an array (see ArrayBase).

See also ArcArray, which also provides copy-on-write behavior but has a reference-counted pointer to the data instead of either a view or a uniquely owned copy.

Implementations§

source§

impl<'a, A, D> CowArray<'a, A, D>where D: Dimension,

Methods specific to CowArray.

See also all methods for ArrayBase

source

pub fn is_view(&self) -> bool

Returns true iff the array is the view (borrowed) variant.

source

pub fn is_owned(&self) -> bool

Returns true iff the array is the owned variant.

Trait Implementations§

source§

impl<'a, A, S, D> From<&'a ArrayBase<S, D>> for CowArray<'a, A, D>where S: Data<Elem = A>, D: Dimension,

source§

fn from(array: &'a ArrayBase<S, D>) -> Self

Create a read-only clone-on-write view of the array.

source§

impl<'a, A, Slice> From<&'a Slice> for CowArray<'a, A, Ix1>where Slice: AsRef<[A]> + ?Sized,

source§

fn from(slice: &'a Slice) -> Self

Create a one-dimensional clone-on-write view of the data in slice.

Panics if the slice length is greater than isize::MAX.

use ndarray::{array, CowArray};

let array = CowArray::from(&[1., 2., 3., 4.]);
assert!(array.is_view());
assert_eq!(array, array![1., 2., 3., 4.]);
source§

impl<'a, A, D> From<ArrayBase<OwnedRepr<A>, D>> for CowArray<'a, A, D>where D: Dimension,

source§

fn from(array: Array<A, D>) -> CowArray<'a, A, D>

Converts to this type from the input type.
source§

impl<'a, A, D> From<ArrayBase<ViewRepr<&'a A>, D>> for CowArray<'a, A, D>where D: Dimension,

source§

fn from(view: ArrayView<'a, A, D>) -> CowArray<'a, A, D>

Converts to this type from the input type.
source§

impl<A, D> IntoIterator for CowArray<'_, A, D>where D: Dimension, A: Clone,

§

type Item = A

The type of the elements being iterated over.
§

type IntoIter = IntoIter<A, D>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more