Skip to content

Commit cb05c2e

Browse files
committed
Add into_scalar method for Array0
1 parent 0a02be3 commit cb05c2e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/impl_owned_array.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
use imp_prelude::*;
22

3+
/// Methods specific to `Array0`.
4+
///
5+
/// ***See also all methods for [`ArrayBase`]***
6+
///
7+
/// [`ArrayBase`]: struct.ArrayBase.html
8+
impl<A> Array<A, Ix0> {
9+
/// Returns the single element in the array without cloning it.
10+
///
11+
/// ```
12+
/// use ndarray::{arr0, Array0};
13+
///
14+
/// // `Foo` doesn't implement `Clone`.
15+
/// #[derive(Debug, Eq, PartialEq)]
16+
/// struct Foo;
17+
///
18+
/// let array: Array0<Foo> = arr0(Foo);
19+
/// let scalar: Foo = array.into_scalar();
20+
/// assert_eq!(scalar, Foo);
21+
/// ```
22+
pub fn into_scalar(mut self) -> A {
23+
self.data.0.remove(0)
24+
}
25+
}
26+
327
/// Methods specific to `Array`.
428
///
529
/// ***See also all methods for [`ArrayBase`]***

0 commit comments

Comments
 (0)