Skip to content

Commit 43ae187

Browse files
committed
Some Result combinations work like an Option.
1 parent 6a2e422 commit 43ae187

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/src/result.rs

+15
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,21 @@
224224
//! [`Err(E)`]: Err
225225
//! [io::Error]: ../../std/io/struct.Error.html "io::Error"
226226
//!
227+
//! # Representation
228+
//!
229+
//! In some cases, [`Result<T, E>`] will gain the same size, alignment, and ABI
230+
//! guarantees as [`Option<T>`] has. One of either the `T` or `E` type must be a
231+
//! type that qualifies for `Option` guarantees, and the *other* type must meet
232+
//! all of the following conditions:
233+
//! * Is a zero-sized type with alignment 1 (a "1-ZST").
234+
//! * Has no fields.
235+
//! * Does not have the #[non_exhaustive] attribute.
236+
//!
237+
//! For example, `Result<NonZeroI32, ()>` or `Result<(), NonZeroI32>` would both
238+
//! have the same guarantees as `Option<NonZeroI32>`. The only difference is the
239+
//! implied semantics: `Result<NonZeroI32, ()>` is "a non-zero success value"
240+
//! while `Result<(), NonZeroI32>` is "a non-zero error value".
241+
//!
227242
//! # Method overview
228243
//!
229244
//! In addition to working with pattern matching, [`Result`] provides a

0 commit comments

Comments
 (0)