Skip to content

Commit a214911

Browse files
committed
Added Arc::try_pin
This helper is in line with other other allocation helpers on Arc.
1 parent b919797 commit a214911

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/alloc/src/sync.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use core::marker::{PhantomData, Unpin, Unsize};
1919
use core::mem::size_of_val;
2020
use core::mem::{self, align_of_val_raw};
2121
use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver};
22-
#[cfg(not(no_global_oom_handling))]
2322
use core::pin::Pin;
2423
use core::ptr::{self, NonNull};
2524
#[cfg(not(no_global_oom_handling))]
@@ -494,6 +493,13 @@ impl<T> Arc<T> {
494493
unsafe { Pin::new_unchecked(Arc::new(data)) }
495494
}
496495

496+
/// Constructs a new `Pin<Arc<T>>`, return an error if allocation fails.
497+
#[unstable(feature = "allocator_api", issue = "32838")]
498+
#[inline]
499+
pub fn try_pin(data: T) -> Result<Pin<Arc<T>>, AllocError> {
500+
unsafe { Ok(Pin::new_unchecked(Arc::try_new(data)?)) }
501+
}
502+
497503
/// Constructs a new `Arc<T>`, returning an error if allocation fails.
498504
///
499505
/// # Examples

0 commit comments

Comments
 (0)