diff --git a/src/impl_cow.rs b/src/impl_cow.rs index b880fd62c..605ba87af 100644 --- a/src/impl_cow.rs +++ b/src/impl_cow.rs @@ -53,3 +53,34 @@ where } } } + +impl<'a, A, Slice: ?Sized> From<&'a Slice> for CowArray<'a, A, Ix1> +where + Slice: AsRef<[A]>, +{ + /// 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.]); + /// ``` + fn from(slice: &'a Slice) -> Self { + Self::from(ArrayView1::from(slice)) + } +} + +impl<'a, A, S, D> From<&'a ArrayBase> for CowArray<'a, A, D> +where + S: Data, + D: Dimension, +{ + /// Create a read-only clone-on-write view of the array. + fn from(array: &'a ArrayBase) -> Self { + Self::from(array.view()) + } +}