Removed trailing whitespace
This commit is contained in:
parent
c351107cdc
commit
0974026a5d
1 changed files with 7 additions and 7 deletions
|
@ -173,32 +173,32 @@ use crate::ptr;
|
||||||
/// ## Initializing a struct field-by-field
|
/// ## Initializing a struct field-by-field
|
||||||
///
|
///
|
||||||
/// You can use `MaybeUninit<T>`, and the [`std::ptr::addr_of_mut`] macro, to initialize structs field by field:
|
/// You can use `MaybeUninit<T>`, and the [`std::ptr::addr_of_mut`] macro, to initialize structs field by field:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::mem::MaybeUninit;
|
/// use std::mem::MaybeUninit;
|
||||||
/// use std::ptr::addr_of_mut;
|
/// use std::ptr::addr_of_mut;
|
||||||
///
|
///
|
||||||
/// #[derive(Debug, PartialEq)]
|
/// #[derive(Debug, PartialEq)]
|
||||||
/// pub struct Foo {
|
/// pub struct Foo {
|
||||||
/// name: String,
|
/// name: String,
|
||||||
/// list: Vec<u8>,
|
/// list: Vec<u8>,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let foo = {
|
/// let foo = {
|
||||||
/// let mut uninit: MaybeUninit<Foo> = MaybeUninit::uninit();
|
/// let mut uninit: MaybeUninit<Foo> = MaybeUninit::uninit();
|
||||||
/// let ptr = uninit.as_mut_ptr();
|
/// let ptr = uninit.as_mut_ptr();
|
||||||
///
|
///
|
||||||
/// // Initializing the `name` field
|
/// // Initializing the `name` field
|
||||||
/// unsafe { addr_of_mut!((*ptr).name).write("Bob".to_string()); }
|
/// unsafe { addr_of_mut!((*ptr).name).write("Bob".to_string()); }
|
||||||
///
|
///
|
||||||
/// // Initializing the `list` field
|
/// // Initializing the `list` field
|
||||||
/// // If there was a panic here, then the `String` in the `name` field would be leaked.
|
/// // If there was a panic here, then the `String` in the `name` field would be leaked.
|
||||||
/// unsafe { addr_of_mut!((*ptr).list).write(vec![0, 1, 2]); }
|
/// unsafe { addr_of_mut!((*ptr).list).write(vec![0, 1, 2]); }
|
||||||
///
|
///
|
||||||
/// // All the fields are initialized, so we call `assume_init` to get an initialized Foo.
|
/// // All the fields are initialized, so we call `assume_init` to get an initialized Foo.
|
||||||
/// unsafe { uninit.assume_init() }
|
/// unsafe { uninit.assume_init() }
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// foo,
|
/// foo,
|
||||||
/// Foo {
|
/// Foo {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue