1
Fork 0

Rollup merge of #68692 - jyn514:vec-from-array, r=LukasKalbertodt

impl From<[T; N]> for Vec<T>

Closes https://github.com/rust-lang/rust/issues/67963
This commit is contained in:
Mazdak Farrokhzad 2020-03-29 11:50:10 +02:00 committed by GitHub
commit c51fcb5f38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 7 deletions

View file

@ -1,3 +1,4 @@
// ignore-tidy-filelength
//! A contiguous growable array type with heap-allocated contents, written
//! `Vec<T>`.
//!
@ -2398,6 +2399,21 @@ impl<T: Clone> From<&mut [T]> for Vec<T> {
}
}
#[stable(feature = "vec_from_array", since = "1.44.0")]
impl<T, const N: usize> From<[T; N]> for Vec<T>
where
[T; N]: LengthAtMost32,
{
#[cfg(not(test))]
fn from(s: [T; N]) -> Vec<T> {
<[T]>::into_vec(box s)
}
#[cfg(test)]
fn from(s: [T; N]) -> Vec<T> {
crate::slice::into_vec(box s)
}
}
#[stable(feature = "vec_from_cow_slice", since = "1.14.0")]
impl<'a, T> From<Cow<'a, [T]>> for Vec<T>
where