Skip to content

Commit

Permalink
Add MaybeUninit::new
Browse files Browse the repository at this point in the history
Sometimes it *is* initialized!
  • Loading branch information
SimonSapin committed Oct 21, 2018
1 parent 12a88a6 commit ac18635
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#![feature(const_fn)]
#![feature(const_int_ops)]
#![feature(const_fn_union)]
#![feature(const_manually_drop_new)]
#![feature(custom_attribute)]
#![feature(doc_cfg)]
#![feature(doc_spotlight)]
Expand Down
9 changes: 9 additions & 0 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,15 @@ pub union MaybeUninit<T> {
}

impl<T> MaybeUninit<T> {
/// Create a new `MaybeUninit` initialized with the given value.
///
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
#[unstable(feature = "maybe_uninit", issue = "53491")]
pub const fn new(val: T) -> MaybeUninit<T> {
MaybeUninit { value: ManuallyDrop::new(val) }
}

/// Create a new `MaybeUninit` in an uninitialized state.
///
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
Expand Down

0 comments on commit ac18635

Please sign in to comment.