Skip to content

Commit 4a97525

Browse files
jturner314bluss
authored andcommitted
Implement From<&'a Slice> for CowArray<'a, A, Ix1>
1 parent daaf625 commit 4a97525

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/impl_cow.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,23 @@ where
5151
}
5252
}
5353
}
54+
55+
impl<'a, A, Slice: ?Sized> From<&'a Slice> for CowArray<'a, A, Ix1>
56+
where
57+
Slice: AsRef<[A]>,
58+
{
59+
/// Create a one-dimensional clone-on-write view of the data in `slice`.
60+
///
61+
/// **Panics** if the slice length is greater than [`isize::MAX`].
62+
///
63+
/// ```
64+
/// use ndarray::{array, CowArray};
65+
///
66+
/// let array = CowArray::from(&[1., 2., 3., 4.]);
67+
/// assert!(array.is_view());
68+
/// assert_eq!(array, array![1., 2., 3., 4.]);
69+
/// ```
70+
fn from(slice: &'a Slice) -> Self {
71+
Self::from(ArrayView1::from(slice))
72+
}
73+
}

0 commit comments

Comments
 (0)