|  | 
| 228 | 228 | //! [`Err(E)`]: Err | 
| 229 | 229 | //! [io::Error]: ../../std/io/struct.Error.html "io::Error" | 
| 230 | 230 | //! | 
|  | 231 | +//! # Representation | 
|  | 232 | +//! | 
|  | 233 | +//! In some cases, [`Result<T, E>`] will gain the same size, alignment, and ABI | 
|  | 234 | +//! guarantees as [`Option<U>`] has. One of either the `T` or `E` type must be a | 
|  | 235 | +//! type that qualifies for the `Option` [representation guarantees][opt-rep], | 
|  | 236 | +//! and the *other* type must meet all of the following conditions: | 
|  | 237 | +//! * Is a zero-sized type with alignment 1 (a "1-ZST"). | 
|  | 238 | +//! * Has no fields. | 
|  | 239 | +//! * Does not have the `#[non_exhaustive]` attribute. | 
|  | 240 | +//! | 
|  | 241 | +//! For example, `NonZeroI32` qualifies for the `Option` representation | 
|  | 242 | +//! guarantees, and `()` is a zero-sized type with alignment 1, no fields, and | 
|  | 243 | +//! it isn't `non_exhaustive`. This means that both `Result<NonZeroI32, ()>` and | 
|  | 244 | +//! `Result<(), NonZeroI32>` have the same size, alignment, and ABI guarantees | 
|  | 245 | +//! as `Option<NonZeroI32>`. The only difference is the implied semantics: | 
|  | 246 | +//! * `Option<NonZeroI32>` is "a non-zero i32 might be present" | 
|  | 247 | +//! * `Result<NonZeroI32, ()>` is "a non-zero i32 success result, if any" | 
|  | 248 | +//! * `Result<(), NonZeroI32>` is "a non-zero i32 error result, if any" | 
|  | 249 | +//! | 
|  | 250 | +//! [opt-rep]: ../option/index.html#representation "Option Representation" | 
|  | 251 | +//! | 
| 231 | 252 | //! # Method overview | 
| 232 | 253 | //! | 
| 233 | 254 | //! In addition to working with pattern matching, [`Result`] provides a | 
|  | 
0 commit comments