diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index bf01b2082eda2..be9832267810c 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2406,6 +2406,27 @@ impl From for Rc { } } +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "shared_from_array", since = "CURRENT_RUSTC_VERSION")] +impl From<[T; N]> for Rc<[T]> { + /// Converts a [`[T; N]`](prim@array) into an `Rc<[T]>`. + /// + /// The conversion moves the array into a newly allocated `Rc`. + /// + /// # Example + /// + /// ``` + /// # use std::rc::Rc; + /// let original: [i32; 3] = [1, 2, 3]; + /// let shared: Rc<[i32]> = Rc::from(original); + /// assert_eq!(&[1, 2, 3], &shared[..]); + /// ``` + #[inline] + fn from(v: [T; N]) -> Rc<[T]> { + Rc::<[T; N]>::from(v) + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] impl From<&[T]> for Rc<[T]> { diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index c2202f2fce553..26fd715c31be0 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3269,6 +3269,27 @@ impl From for Arc { } } +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "shared_from_array", since = "CURRENT_RUSTC_VERSION")] +impl 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 From<&[T]> for Arc<[T]> {