Skip to content

Commit

Permalink
Rollup merge of rust-lang#85579 - alex:patch-1, r=yaahc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored Jul 15, 2021
2 parents 9c10781 + 1eb439a commit fc14c48
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ impl<T> Arc<T> {
unsafe { Pin::new_unchecked(Arc::new(data)) }
}

/// Constructs a new `Pin<Arc<T>>, return an error if allocation fails.
#[unstable(feature = "allocator_api", issue = "32838")]
#[inline]
pub fn try_pin(data: T) -> Result<Pin<Arc<T>>, AllocError> {
unsafe { Ok(Pin::new_unchecked(Arc::try_new(data)?)) }
}

/// Constructs a new `Arc<T>`, returning an error if allocation fails.
///
/// # Examples
Expand Down

0 comments on commit fc14c48

Please sign in to comment.