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§
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,
impl<'a, A, S, D> From<&'a ArrayBase<S, D>> for CowArray<'a, A, D>where S: Data<Elem = A>, D: Dimension,
source§impl<'a, A, Slice> From<&'a Slice> for CowArray<'a, A, Ix1>where
Slice: AsRef<[A]> + ?Sized,
impl<'a, A, Slice> From<&'a Slice> for CowArray<'a, A, Ix1>where Slice: AsRef<[A]> + ?Sized,
source§fn from(slice: &'a Slice) -> Self
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.]);