Skip to content

Commit 9d38ce3

Browse files
authored
Added Arc::try_pin
This helper is in line with other other allocation helpers on Arc.
1 parent 104a3c3 commit 9d38ce3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/alloc/src/sync.rs

+7
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ impl<T> Arc<T> {
489489
pub fn pin(data: T) -> Pin<Arc<T>> {
490490
unsafe { Pin::new_unchecked(Arc::new(data)) }
491491
}
492+
493+
/// Constructs a new `Pin<Arc<T>>, return an error if allocation fails.
494+
#[unstable(feature = "allocator_api", issue = "32838")]
495+
#[inline]
496+
pub fn try_pin(data: T) -> Result<Pin<Arc<T>>, AllocError> {
497+
unsafe { Ok(Pin::new_unchecked(Arc::try_new(data)?)) }
498+
}
492499

493500
/// Constructs a new `Arc<T>`, returning an error if allocation fails.
494501
///

0 commit comments

Comments
 (0)