Skip to content

Commit cc632ba

Browse files
authored
Unrolled build for rust-lang#138968
Rollup merge of rust-lang#138968 - Natural-selection1:update-Result-doc, r=Amanieu Update the index of Result to make the summary more comprehensive fix rust-lang#138966 This PR and rust-lang#138957 are twin PR r? `@Amanieu`
2 parents e3e432d + cdc7298 commit cc632ba

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

library/core/src/result.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,14 @@
259259
//! The [`is_ok`] and [`is_err`] methods return [`true`] if the [`Result`]
260260
//! is [`Ok`] or [`Err`], respectively.
261261
//!
262+
//! The [`is_ok_and`] and [`is_err_and`] methods apply the provided function
263+
//! to the contents of the [`Result`] to produce a boolean value. If the [`Result`] does not have the expected variant
264+
//! then [`false`] is returned instead without executing the function.
265+
//!
262266
//! [`is_err`]: Result::is_err
263267
//! [`is_ok`]: Result::is_ok
268+
//! [`is_ok_and`]: Result::is_ok_and
269+
//! [`is_err_and`]: Result::is_err_and
264270
//!
265271
//! ## Adapters for working with references
266272
//!
@@ -287,6 +293,7 @@
287293
//! (which must implement the [`Default`] trait)
288294
//! * [`unwrap_or_else`] returns the result of evaluating the provided
289295
//! function
296+
//! * [`unwrap_unchecked`] produces *[undefined behavior]*
290297
//!
291298
//! The panicking methods [`expect`] and [`unwrap`] require `E` to
292299
//! implement the [`Debug`] trait.
@@ -297,17 +304,22 @@
297304
//! [`unwrap_or`]: Result::unwrap_or
298305
//! [`unwrap_or_default`]: Result::unwrap_or_default
299306
//! [`unwrap_or_else`]: Result::unwrap_or_else
307+
//! [`unwrap_unchecked`]: Result::unwrap_unchecked
308+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
300309
//!
301310
//! These methods extract the contained value in a [`Result<T, E>`] when it
302311
//! is the [`Err`] variant. They require `T` to implement the [`Debug`]
303312
//! trait. If the [`Result`] is [`Ok`]:
304313
//!
305314
//! * [`expect_err`] panics with a provided custom message
306315
//! * [`unwrap_err`] panics with a generic message
316+
//! * [`unwrap_err_unchecked`] produces *[undefined behavior]*
307317
//!
308318
//! [`Debug`]: crate::fmt::Debug
309319
//! [`expect_err`]: Result::expect_err
310320
//! [`unwrap_err`]: Result::unwrap_err
321+
//! [`unwrap_err_unchecked`]: Result::unwrap_err_unchecked
322+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
311323
//!
312324
//! ## Transforming contained values
313325
//!
@@ -330,21 +342,29 @@
330342
//! [`Some(v)`]: Option::Some
331343
//! [`transpose`]: Result::transpose
332344
//!
333-
//! This method transforms the contained value of the [`Ok`] variant:
345+
//! These methods transform the contained value of the [`Ok`] variant:
334346
//!
335347
//! * [`map`] transforms [`Result<T, E>`] into [`Result<U, E>`] by applying
336348
//! the provided function to the contained value of [`Ok`] and leaving
337349
//! [`Err`] values unchanged
350+
//! * [`inspect`] takes ownership of the [`Result`], applies the
351+
//! provided function to the contained value by reference,
352+
//! and then returns the [`Result`]
338353
//!
339354
//! [`map`]: Result::map
355+
//! [`inspect`]: Result::inspect
340356
//!
341-
//! This method transforms the contained value of the [`Err`] variant:
357+
//! These methods transform the contained value of the [`Err`] variant:
342358
//!
343359
//! * [`map_err`] transforms [`Result<T, E>`] into [`Result<T, F>`] by
344360
//! applying the provided function to the contained value of [`Err`] and
345361
//! leaving [`Ok`] values unchanged
362+
//! * [`inspect_err`] takes ownership of the [`Result`], applies the
363+
//! provided function to the contained value of [`Err`] by reference,
364+
//! and then returns the [`Result`]
346365
//!
347366
//! [`map_err`]: Result::map_err
367+
//! [`inspect_err`]: Result::inspect_err
348368
//!
349369
//! These methods transform a [`Result<T, E>`] into a value of a possibly
350370
//! different type `U`:
@@ -578,6 +598,10 @@ impl<T, E> Result<T, E> {
578598
///
579599
/// let x: Result<u32, &str> = Err("hey");
580600
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
601+
///
602+
/// let x: Result<String, &str> = Ok("ownership".to_string());
603+
/// assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true);
604+
/// println!("still alive {:?}", x);
581605
/// ```
582606
#[must_use]
583607
#[inline]
@@ -623,6 +647,10 @@ impl<T, E> Result<T, E> {
623647
///
624648
/// let x: Result<u32, Error> = Ok(123);
625649
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
650+
///
651+
/// let x: Result<u32, String> = Err("ownership".to_string());
652+
/// assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true);
653+
/// println!("still alive {:?}", x);
626654
/// ```
627655
#[must_use]
628656
#[inline]

0 commit comments

Comments
 (0)