Skip to content

Commit fc14c48

Browse files
authored
Rollup merge of rust-lang#85579 - alex:patch-1, r=yaahc
Added Arc::try_pin This helper is in line with other other allocation helpers on Arc. I didn't think this would require an RFC or broader discussion, let me know if that's incorrect.
2 parents 9c10781 + 1eb439a commit fc14c48

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
@@ -494,6 +494,13 @@ impl<T> Arc<T> {
494494
unsafe { Pin::new_unchecked(Arc::new(data)) }
495495
}
496496

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

0 commit comments

Comments
 (0)