Skip to content

Commit

Permalink
Add a warning about Option/Result::and() being eagerly evaluated
Browse files Browse the repository at this point in the history
Copied from `or()`.
  • Loading branch information
ChayimFriedman2 committed Aug 23, 2022
1 parent ee8c31e commit eb2fdd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
/// ```
Expand Down
5 changes: 5 additions & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down

0 comments on commit eb2fdd9

Please sign in to comment.