about summary refs log tree commit diff
path: root/library/alloc/src/sync.rs
diff options
context:
space:
mode:
authorNikolai Vazquez <hello@nikolaivazquez.com>2023-07-24 21:33:16 -0400
committerNikolai Vazquez <hello@nikolaivazquez.com>2023-07-24 22:13:42 -0400
commitb2d35e1f4bc2aa6f2b9745ea515d5d69298b2e52 (patch)
tree2c8178901a11df5d3c2be18b89918ec60ee95edf /library/alloc/src/sync.rs
parent31395ec38250b60b380fd3c27e94756aba3557de (diff)
downloadrust-b2d35e1f4bc2aa6f2b9745ea515d5d69298b2e52.tar.gz
rust-b2d35e1f4bc2aa6f2b9745ea515d5d69298b2e52.zip
Implement `From<[T; N]>` for `Rc<[T]>` and `Arc<[T]>`
Diffstat (limited to 'library/alloc/src/sync.rs')
-rw-r--r--library/alloc/src/sync.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs
index c2202f2fce5..26fd715c31b 100644
--- a/library/alloc/src/sync.rs
+++ b/library/alloc/src/sync.rs
@@ -3270,6 +3270,27 @@ impl<T> From<T> for Arc<T> {
 }
 
 #[cfg(not(no_global_oom_handling))]
+#[stable(feature = "shared_from_array", since = "CURRENT_RUSTC_VERSION")]
+impl<T, const N: usize> From<[T; N]> for Arc<[T]> {
+    /// Converts a [`[T; N]`](prim@array) into an `Arc<[T]>`.
+    ///
+    /// The conversion moves the array into a newly allocated `Arc`.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// # use std::sync::Arc;
+    /// let original: [i32; 3] = [1, 2, 3];
+    /// let shared: Arc<[i32]> = Arc::from(original);
+    /// assert_eq!(&[1, 2, 3], &shared[..]);
+    /// ```
+    #[inline]
+    fn from(v: [T; N]) -> Arc<[T]> {
+        Arc::<[T; N]>::from(v)
+    }
+}
+
+#[cfg(not(no_global_oom_handling))]
 #[stable(feature = "shared_from_slice", since = "1.21.0")]
 impl<T: Clone> From<&[T]> for Arc<[T]> {
     /// Allocate a reference-counted slice and fill it by cloning `v`'s items.