diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-29 11:50:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-29 11:50:10 +0200 |
| commit | c51fcb5f3847cc70de316db0b4c46f23fc8d0d35 (patch) | |
| tree | d25010c3d8e7cc78871c38cfb7acf0d8f8eb2805 /src/liballoc/vec.rs | |
| parent | 8045865873f7cdbb864d0f66ef5ecb0d3ad847b2 (diff) | |
| parent | 3477e67a92878adae48b975915cb7a5c21026cd4 (diff) | |
| download | rust-c51fcb5f3847cc70de316db0b4c46f23fc8d0d35.tar.gz rust-c51fcb5f3847cc70de316db0b4c46f23fc8d0d35.zip | |
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
Diffstat (limited to 'src/liballoc/vec.rs')
| -rw-r--r-- | src/liballoc/vec.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 4769091183a..e171edef736 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -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 |
