diff options
| author | Ivan Tham <pickfire@riseup.net> | 2020-04-13 21:41:45 +0800 |
|---|---|---|
| committer | Ivan Tham <pickfire@riseup.net> | 2020-05-20 17:00:21 +0800 |
| commit | a8ed9aa9f016c60f5fa55326f1f6a30e2be9d83e (patch) | |
| tree | 56f7bf57455b92ce6b730e398c43b04de63513da /src/liballoc | |
| parent | 3a7dfda40a3e798bf086bd58cc7e5e09deb808b5 (diff) | |
| download | rust-a8ed9aa9f016c60f5fa55326f1f6a30e2be9d83e.tar.gz rust-a8ed9aa9f016c60f5fa55326f1f6a30e2be9d83e.zip | |
impl From<[T; N]> for Box<[T]>
Based on https://github.com/rust-lang/rust/pull/68692
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 8ef6090c743..8cc6f04c065 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -865,6 +865,25 @@ impl From<Box<str>> for Box<[u8]> { } } +#[stable(feature = "box_from_array", since = "1.45.0")] +impl<T, const N: usize> From<[T; N]> for Box<[T]> +where + [T; N]: LengthAtMost32, +{ + /// Converts a `[T; N]` into a `Box<[T]>` + /// + /// This conversion moves the array to newly heap-allocated memory. + /// + /// # Examples + /// ```rust + /// let boxed: Box<[u8]> = Box::from([4, 2]); + /// println!("{:?}", boxed); + /// ``` + fn from(array: [T; N]) -> Box<[T]> { + box array + } +} + #[stable(feature = "boxed_slice_try_from", since = "1.43.0")] impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> where |
