From a411a20662caddbb40fa3334619abfd574693eda Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 5 Feb 2020 13:27:59 +0800 Subject: [PATCH 1/2] Don't use the word 'unwrap' to describe core 'unwrap' functions --- src/libcore/option.rs | 2 +- src/libcore/result.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index ad0491f888cc7..b2e5c42844a4b 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1023,7 +1023,7 @@ impl Option { } } - /// Unwraps an option, expecting [`None`] and returning nothing. + /// Consumes an option, expecting [`None`] and returning nothing. /// /// # Panics /// diff --git a/src/libcore/result.rs b/src/libcore/result.rs index bc70dbd62eb52..93a2d9c85535d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -792,7 +792,7 @@ impl Result { } } - /// Unwraps a result, yielding the content of an [`Ok`]. + /// Consumes a result, yielding the content of an [`Ok`]. /// Else, it returns `optb`. /// /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing @@ -824,7 +824,7 @@ impl Result { } } - /// Unwraps a result, yielding the content of an [`Ok`]. + /// Consumes a result, yielding the content of an [`Ok`]. /// If the value is an [`Err`] then it calls `op` with its value. /// /// [`Ok`]: enum.Result.html#variant.Ok @@ -931,7 +931,7 @@ impl Result<&mut T, E> { } impl Result { - /// Unwraps a result, yielding the content of an [`Ok`]. + /// Consumes a result, yielding the content of an [`Ok`]. /// /// # Panics /// @@ -964,7 +964,7 @@ impl Result { } } - /// Unwraps a result, yielding the content of an [`Ok`]. + /// Consumes a result, yielding the content of an [`Ok`]. /// /// # Panics /// @@ -994,7 +994,7 @@ impl Result { } impl Result { - /// Unwraps a result, yielding the content of an [`Err`]. + /// Consumes a result, yielding the content of an [`Err`]. /// /// # Panics /// From 2e5484e651f47d635090053c0c3efa67afa3b312 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 5 Feb 2020 14:09:22 +0800 Subject: [PATCH 2/2] More various unwrap docs more consistent --- src/libcore/option.rs | 14 ++++++++++---- src/libcore/result.rs | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b2e5c42844a4b..f59a21e38aa26 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -382,13 +382,15 @@ impl Option { } } - /// Returns the contained value or a default. + /// Moves the value `v` out of the `Option` if it is [`Some(v)`], + /// or returns a provided a default. /// /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing /// the result of a function call, it is recommended to use [`unwrap_or_else`], /// which is lazily evaluated. /// /// [`unwrap_or_else`]: #method.unwrap_or_else + /// [`Some(v)`]: #variant.Some /// /// # Examples /// @@ -405,7 +407,11 @@ impl Option { } } - /// Returns the contained value or computes it from a closure. + /// Moves the value `v` out of the `Option` if it is [`Some(v)`], + /// or computes it from a closure. + /// + /// [`Some(v)`]: #variant.Some + /// [`None`]: #variant.None /// /// # Examples /// @@ -416,10 +422,10 @@ impl Option { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn unwrap_or_else T>(self, f: F) -> T { + pub fn unwrap_or_else T>(self, op: F) -> T { match self { Some(x) => x, - None => f(), + None => op(), } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 93a2d9c85535d..359b4f1f50817 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -792,14 +792,15 @@ impl Result { } } - /// Consumes a result, yielding the content of an [`Ok`]. - /// Else, it returns `optb`. + /// Moves the value `v` out of the `Result` if it is [`Ok(v)`], + /// or returns a provided default. /// /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing /// the result of a function call, it is recommended to use [`unwrap_or_else`], /// which is lazily evaluated. /// /// [`Ok`]: enum.Result.html#variant.Ok + /// [`Ok(v)`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err /// [`unwrap_or_else`]: #method.unwrap_or_else /// @@ -808,27 +809,27 @@ impl Result { /// Basic usage: /// /// ``` - /// let optb = 2; + /// let default = 2; /// let x: Result = Ok(9); - /// assert_eq!(x.unwrap_or(optb), 9); + /// assert_eq!(x.unwrap_or(default), 9); /// /// let x: Result = Err("error"); - /// assert_eq!(x.unwrap_or(optb), optb); + /// assert_eq!(x.unwrap_or(default), default); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn unwrap_or(self, optb: T) -> T { + pub fn unwrap_or(self, default: T) -> T { match self { Ok(t) => t, - Err(_) => optb, + Err(_) => default, } } - /// Consumes a result, yielding the content of an [`Ok`]. - /// If the value is an [`Err`] then it calls `op` with its value. + /// Moves the value `v` out of the `Result` if it is [`Ok(v)`], + /// or computes it from a closure. /// + /// [`Ok(v)`]: enum.Result.html#variant.Ok /// [`Ok`]: enum.Result.html#variant.Ok - /// [`Err`]: enum.Result.html#variant.Err /// /// # Examples /// @@ -931,13 +932,14 @@ impl Result<&mut T, E> { } impl Result { - /// Consumes a result, yielding the content of an [`Ok`]. + /// Moves the value `v` out of the `Result` if it is [`Ok(v)`]. /// /// # Panics /// /// Panics if the value is an [`Err`], with a panic message provided by the /// [`Err`]'s value. /// + /// [`Ok(v)`]: enum.Result.html#variant.Ok /// [`Ok`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err /// @@ -994,13 +996,14 @@ impl Result { } impl Result { - /// Consumes a result, yielding the content of an [`Err`]. + /// Moves the value `v` out of the `Result` if it is [`Err(v)`]. /// /// # Panics /// /// Panics if the value is an [`Ok`], with a custom panic message provided /// by the [`Ok`]'s value. /// + /// [`Err(v)`]: enum.Result.html#variant.Err /// [`Ok`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err ///