Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add From<Box<[A]>> for 1-D owned arrays #1016

Merged
merged 1 commit into from Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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