Skip to content

Commit b7df252

Browse files
committed
fix some typos in the code and add playground link
1 parent 8e08797 commit b7df252

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

text/0000-uninitialized-uninhabited.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ library as a replacement.
159159
Add the aforementioned `MaybeUninit` type to the standard library:
160160

161161
```rust
162-
union MaybeUninit<T> {
162+
pub union MaybeUninit<T> {
163163
uninit: (),
164164
value: ManuallyDrop<T>,
165165
}
166166
```
167167

168168
The type should have at least the following interface
169+
([Playground link](https://play.rust-lang.org/?gist=81f5ab9a7e7107c9583de21382ef4333&version=nightly&mode=debug&edition=2015)):
169170

170171
```rust
171172
impl<T> MaybeUninit<T> {
@@ -188,8 +189,8 @@ impl<T> MaybeUninit<T> {
188189
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
189190
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
190191
pub fn zeroed() -> MaybeUninit<T> {
191-
let mut u = uninitialized();
192-
u.as_mut_ptr().write_bytes(0u8, 1);
192+
let mut u = MaybeUninit::<T>::uninitialized();
193+
unsafe { u.as_mut_ptr().write_bytes(0u8, 1); }
193194
u
194195
}
195196

@@ -233,13 +234,13 @@ impl<T> MaybeUninit<T> {
233234
/// Get a pointer to the contained value. Reading from this pointer will be undefined
234235
/// behavior unless the `MaybeUninit` is initialized.
235236
pub fn as_ptr(&self) -> *const T {
236-
&*self.value *const T
237+
unsafe { &*self.value as *const T }
237238
}
238239

239240
/// Get a mutable pointer to the contained value. Reading from this pointer will be undefined
240241
/// behavior unless the `MaybeUninit` is initialized.
241242
pub fn as_mut_ptr(&mut self) -> *mut T {
242-
&mut *self.value *mut T
243+
unsafe { &mut *self.value as *mut T }
243244
}
244245
}
245246
```

0 commit comments

Comments
 (0)