Skip to content

Commit

Permalink
Merge pull request #1016 from jturner314/from-boxed-slice
Browse files Browse the repository at this point in the history
Add From<Box<[A]>> for 1-D owned arrays
  • Loading branch information
bluss committed Jun 5, 2021
2 parents f5c18a5 + 0f15056 commit 27d798b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/arraytraits.rs
Expand Up @@ -11,6 +11,7 @@ use std::iter::FromIterator;
use std::iter::IntoIterator;
use std::mem;
use std::ops::{Index, IndexMut};
use alloc::boxed::Box;
use alloc::vec::Vec;

use crate::imp_prelude::*;
Expand Down Expand Up @@ -148,6 +149,18 @@ where
{
}

impl<A, S> From<Box<[A]>> for ArrayBase<S, Ix1>
where
S: DataOwned<Elem = A>,
{
/// Create a one-dimensional array from a boxed slice (no copying needed).
///
/// **Panics** if the length is greater than `isize::MAX`.
fn from(b: Box<[A]>) -> Self {
Self::from_vec(b.into_vec())
}
}

impl<A, S> From<Vec<A>> for ArrayBase<S, Ix1>
where
S: DataOwned<Elem = A>,
Expand Down

0 comments on commit 27d798b

Please sign in to comment.