Auto merge of #114041 - nvzqz:nvzqz/shared_from_array, r=dtolnay · rust-lang/rust@46da927 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -2408,6 +2408,27 @@ impl From for Rc {
2408 2408 }
2409 2409 }
2410 2410
2411 +#[cfg(not(no_global_oom_handling))]
2412 +#[stable(feature = "shared_from_array", since = "CURRENT_RUSTC_VERSION")]
2413 +impl<T, const N: usize> From<[T; N]> for Rc<[T]> {
2414 +/// Converts a [`[T; N]`](prim@array) into an `Rc<[T]>`.
2415 + ///
2416 + /// The conversion moves the array into a newly allocated `Rc`.
2417 + ///
2418 + /// # Example
2419 + ///
2420 + /// ```
2421 + /// # use std::rc::Rc;
2422 + /// let original: [i32; 3] = [1, 2, 3];
2423 + /// let shared: Rc<[i32]> = Rc::from(original);
2424 + /// assert_eq!(&[1, 2, 3], &shared[..]);
2425 + /// ```
2426 + #[inline]
2427 +fn from(v: [T; N]) -> Rc<[T]> {
2428 +Rc::<[T; N]>::from(v)
2429 +}
2430 +}
2431 +
2411 2432 #[cfg(not(no_global_oom_handling))]
2412 2433 #[stable(feature = "shared_from_slice", since = "1.21.0")]
2413 2434 impl<T: Clone> From<&[T]> for Rc<[T]> {
Original file line number Diff line number Diff line change
@@ -3269,6 +3269,27 @@ impl From for Arc {
3269 3269 }
3270 3270 }
3271 3271
3272 +#[cfg(not(no_global_oom_handling))]
3273 +#[stable(feature = "shared_from_array", since = "CURRENT_RUSTC_VERSION")]
3274 +impl<T, const N: usize> From<[T; N]> for Arc<[T]> {
3275 +/// Converts a [`[T; N]`](prim@array) into an `Arc<[T]>`.
3276 + ///
3277 + /// The conversion moves the array into a newly allocated `Arc`.
3278 + ///
3279 + /// # Example
3280 + ///
3281 + /// ```
3282 + /// # use std::sync::Arc;
3283 + /// let original: [i32; 3] = [1, 2, 3];
3284 + /// let shared: Arc<[i32]> = Arc::from(original);
3285 + /// assert_eq!(&[1, 2, 3], &shared[..]);
3286 + /// ```
3287 + #[inline]
3288 +fn from(v: [T; N]) -> Arc<[T]> {
3289 +Arc::<[T; N]>::from(v)
3290 +}
3291 +}
3292 +
3272 3293 #[cfg(not(no_global_oom_handling))]
3273 3294 #[stable(feature = "shared_from_slice", since = "1.21.0")]
3274 3295 impl<T: Clone> From<&[T]> for Arc<[T]> {