diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2021-05-22 10:24:50 -0400 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2021-07-15 07:32:05 -0400 |
| commit | a214911b773b299e37dea0c6f2644a26a5756d4b (patch) | |
| tree | 002243b3357259b8371edce5032d1a1c4564b5c4 /library/alloc/src/sync.rs | |
| parent | b9197978a90be6f7570741eabe2da175fec75375 (diff) | |
| download | rust-a214911b773b299e37dea0c6f2644a26a5756d4b.tar.gz rust-a214911b773b299e37dea0c6f2644a26a5756d4b.zip | |
Added Arc::try_pin
This helper is in line with other other allocation helpers on Arc.
Diffstat (limited to 'library/alloc/src/sync.rs')
| -rw-r--r-- | library/alloc/src/sync.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 4b34a7dc894..d821e715622 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -19,7 +19,6 @@ use core::marker::{PhantomData, Unpin, Unsize}; use core::mem::size_of_val; use core::mem::{self, align_of_val_raw}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; -#[cfg(not(no_global_oom_handling))] use core::pin::Pin; use core::ptr::{self, NonNull}; #[cfg(not(no_global_oom_handling))] @@ -494,6 +493,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 |
