Clarify some parts by applying the suggestions from review
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
This commit is contained in:
parent
2e21af2859
commit
614f7738ba
1 changed files with 7 additions and 6 deletions
|
@ -1625,9 +1625,9 @@ mod dyn_keyword {}
|
||||||
/// The [Rust equivalent of a C-style union][union].
|
/// The [Rust equivalent of a C-style union][union].
|
||||||
///
|
///
|
||||||
/// A `union` looks like a [`struct`] in terms of declaration, but all of its
|
/// A `union` looks like a [`struct`] in terms of declaration, but all of its
|
||||||
/// fields exist simultaneously, superimposed over one another. For instance,
|
/// fields exist in the same memory, superimposed over one another. For instance,
|
||||||
/// if we wanted some bits in memory that we sometimes interpret as a `u32` and
|
/// if we wanted some bits in memory that we sometimes interpret as a `u32` and
|
||||||
/// sometimes as an `f32`, we would write:
|
/// sometimes as an `f32`, we could write:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// union IntOrFloat {
|
/// union IntOrFloat {
|
||||||
|
@ -1647,6 +1647,7 @@ mod dyn_keyword {}
|
||||||
///
|
///
|
||||||
/// It is possible to use pattern matching on `union`s. A single field name must
|
/// It is possible to use pattern matching on `union`s. A single field name must
|
||||||
/// be used and it must match the name of one of the `union`'s field.
|
/// be used and it must match the name of one of the `union`'s field.
|
||||||
|
/// Like reading from a `union`, pattern matching on a `union` requires `unsafe`.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// union IntOrFloat {
|
/// union IntOrFloat {
|
||||||
|
@ -1659,7 +1660,7 @@ mod dyn_keyword {}
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// match u {
|
/// match u {
|
||||||
/// IntOrFloat { i: 10 } => println!("Found exactly ten!"),
|
/// IntOrFloat { i: 10 } => println!("Found exactly ten!"),
|
||||||
/// // The field name is used to deduce the type
|
/// // Matching the field `f` provides an `f32`.
|
||||||
/// IntOrFloat { f } => println!("Found f = {} !", f),
|
/// IntOrFloat { f } => println!("Found f = {} !", f),
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
|
@ -1667,8 +1668,8 @@ mod dyn_keyword {}
|
||||||
///
|
///
|
||||||
/// # References to union fields
|
/// # References to union fields
|
||||||
///
|
///
|
||||||
/// All fields in a union are all at the same place in memory which means
|
/// All fields in a `union` are all at the same place in memory which means
|
||||||
/// borrowing one borrows all of them, for the same duration:
|
/// borrowing one borrows the entire `union`, for the same lifetime:
|
||||||
///
|
///
|
||||||
/// ```rust,compile_fail,E0502
|
/// ```rust,compile_fail,E0502
|
||||||
/// union IntOrFloat {
|
/// union IntOrFloat {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue