diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2022-08-23 16:15:09 +0000 |
|---|---|---|
| committer | Chayim Refael Friedman <chayimfr@gmail.com> | 2022-08-23 16:15:09 +0000 |
| commit | eb2fdd917ef05184c7ef2eab707183b07d68ff5e (patch) | |
| tree | 68692058b42f336007bf4a90c6d794be291f8c99 | |
| parent | ee8c31e64d229cac4eba6d8f03bb70e16f34a14b (diff) | |
| download | rust-eb2fdd917ef05184c7ef2eab707183b07d68ff5e.tar.gz rust-eb2fdd917ef05184c7ef2eab707183b07d68ff5e.zip | |
Add a warning about `Option/Result::and()` being eagerly evaluated
Copied from `or()`.
| -rw-r--r-- | library/core/src/option.rs | 6 | ||||
| -rw-r--r-- | library/core/src/result.rs | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index bca73cb770f..93417586363 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1189,6 +1189,12 @@ impl<T> Option<T> { /// Returns [`None`] if the option is [`None`], otherwise returns `optb`. /// + /// Arguments passed to `and` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use [`and_then`], which is + /// lazily evaluated. + /// + /// [`and_then`]: Option::and_then + /// /// # Examples /// /// ``` diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 45b052c824d..75dcb4cdba9 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1285,6 +1285,11 @@ impl<T, E> Result<T, E> { /// Returns `res` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`. /// + /// Arguments passed to `and` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use [`and_then`], which is + /// lazily evaluated. + /// + /// [`and_then`]: Result::and_then /// /// # Examples /// |
