Thanks to visit codestin.com
Credit goes to docs.rs

ndarray/
impl_clone.rs

1// Copyright 2014-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
9use crate::imp_prelude::*;
10use crate::RawDataClone;
11
12impl<S: RawDataClone, D: Clone> Clone for ArrayBase<S, D>
13{
14    fn clone(&self) -> ArrayBase<S, D>
15    {
16        // safe because `clone_with_ptr` promises to provide equivalent data and ptr
17        unsafe {
18            let (data, ptr) = self.data.clone_with_ptr(self.ptr);
19            ArrayBase {
20                data,
21                ptr,
22                dim: self.dim.clone(),
23                strides: self.strides.clone(),
24            }
25        }
26    }
27
28    /// `Array` implements `.clone_from()` to reuse an array's existing
29    /// allocation. Semantically equivalent to `*self = other.clone()`, but
30    /// potentially more efficient.
31    fn clone_from(&mut self, other: &Self)
32    {
33        unsafe {
34            self.ptr = self.data.clone_from_with_ptr(&other.data, other.ptr);
35            self.dim.clone_from(&other.dim);
36            self.strides.clone_from(&other.strides);
37        }
38    }
39}
40
41impl<S: RawDataClone + Copy, D: Copy> Copy for ArrayBase<S, D> {}