File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -173,32 +173,32 @@ use crate::ptr;
173173/// ## Initializing a struct field-by-field
174174///
175175/// You can use `MaybeUninit<T>`, and the [`std::ptr::addr_of_mut`] macro, to initialize structs field by field:
176- ///
176+ ///
177177/// ```rust
178178/// use std::mem::MaybeUninit;
179179/// use std::ptr::addr_of_mut;
180- ///
180+ ///
181181/// #[derive(Debug, PartialEq)]
182182/// pub struct Foo {
183183/// name: String,
184184/// list: Vec<u8>,
185185/// }
186- ///
186+ ///
187187/// let foo = {
188188/// let mut uninit: MaybeUninit<Foo> = MaybeUninit::uninit();
189189/// let ptr = uninit.as_mut_ptr();
190- ///
190+ ///
191191/// // Initializing the `name` field
192192/// unsafe { addr_of_mut!((*ptr).name).write("Bob".to_string()); }
193- ///
193+ ///
194194/// // Initializing the `list` field
195195/// // If there was a panic here, then the `String` in the `name` field would be leaked.
196196/// unsafe { addr_of_mut!((*ptr).list).write(vec![0, 1, 2]); }
197- ///
197+ ///
198198/// // All the fields are initialized, so we call `assume_init` to get an initialized Foo.
199199/// unsafe { uninit.assume_init() }
200200/// };
201- ///
201+ ///
202202/// assert_eq!(
203203/// foo,
204204/// Foo {
You can’t perform that action at this time.
0 commit comments