From f94fa6bee3bf1c7d313452db0bafbce0960196ff Mon Sep 17 00:00:00 2001 From: Lokathor Date: Tue, 7 May 2024 18:08:36 -0600 Subject: [PATCH] Some Result combinations work like an Option. --- library/core/src/result.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/library/core/src/result.rs b/library/core/src/result.rs index b2b627fe6a9cc..16c97284104d4 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -224,6 +224,21 @@ //! [`Err(E)`]: Err //! [io::Error]: ../../std/io/struct.Error.html "io::Error" //! +//! # Representation +//! +//! In some cases, [`Result`] will gain the same size, alignment, and ABI +//! guarantees as [`Option`] has. One of either the `T` or `E` type must be a +//! type that qualifies for `Option` guarantees, and the *other* type must meet +//! all of the following conditions: +//! * Is a zero-sized type with alignment 1 (a "1-ZST"). +//! * Has no fields. +//! * Does not have the #[non_exhaustive] attribute. +//! +//! For example, `Result` or `Result<(), NonZeroI32>` would both +//! have the same guarantees as `Option`. The only difference is the +//! implied semantics: `Result` is "a non-zero success value" +//! while `Result<(), NonZeroI32>` is "a non-zero error value". +//! //! # Method overview //! //! In addition to working with pattern matching, [`Result`] provides a