Address ThinBox::try_new PR review
This commit is contained in:
parent
3c880f2405
commit
ea6944a065
@ -67,20 +67,19 @@ pub fn new(value: T) -> Self {
|
||||
let ptr = WithOpaqueHeader::new(meta, value);
|
||||
ThinBox { ptr, _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "thin_box", issue = "92791")]
|
||||
impl<T> ThinBox<T> {
|
||||
/// Moves a type to the heap with its [`Metadata`] stored in the heap allocation instead of on
|
||||
/// the stack. Returns an error if allocation fails, instead of aborting.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(allocator_api)]
|
||||
/// #![feature(thin_box)]
|
||||
/// use std::boxed::ThinBox;
|
||||
///
|
||||
/// let five = ThinBox::new(5);
|
||||
/// let five = ThinBox::try_new(5)?;
|
||||
/// # Ok::<(), std::alloc::AllocError>(())
|
||||
/// ```
|
||||
///
|
||||
/// [`Metadata`]: core::ptr::Pointee::Metadata
|
||||
|
Loading…
Reference in New Issue
Block a user