Address ThinBox::try_new PR review

This commit is contained in:
David Tolnay 2024-02-11 11:15:21 -08:00
parent 3c880f2405
commit ea6944a065
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -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