ndarray/
impl_1d.rs

1// Copyright 2016 bluss and ndarray developers.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! Methods for one-dimensional arrays.
10use alloc::vec::Vec;
11use crate::imp_prelude::*;
12
13/// # Methods For 1-D Arrays
14impl<A, S> ArrayBase<S, Ix1>
15where
16    S: RawData<Elem = A>,
17{
18    /// Return an vector with the elements of the one-dimensional array.
19    pub fn to_vec(&self) -> Vec<A>
20    where
21        A: Clone,
22        S: Data,
23    {
24        if let Some(slc) = self.as_slice() {
25            slc.to_vec()
26        } else {
27            crate::iterators::to_vec(self.iter().cloned())
28        }
29    }
30}