X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Falloc%2Fsrc%2Fsync.rs;h=d821e71562212ed86fd7d083331da0b78f4d6909;hb=12ed22ffe44d7b06e94c2fe0003ef96a20cf4b98;hp=4b34a7dc894ae327d426b41a81c59502a25b4189;hpb=9bbc470e9779436d787ccda9924826176030b714;p=rust.git 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::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 @@ pub fn pin(data: T) -> Pin> { unsafe { Pin::new_unchecked(Arc::new(data)) } } + /// Constructs a new `Pin>`, return an error if allocation fails. + #[unstable(feature = "allocator_api", issue = "32838")] + #[inline] + pub fn try_pin(data: T) -> Result>, AllocError> { + unsafe { Ok(Pin::new_unchecked(Arc::try_new(data)?)) } + } + /// Constructs a new `Arc`, returning an error if allocation fails. /// /// # Examples