diff --git a/src/libcore/option.rs b/src/libcore/option.rs index ad0491f888cc7..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(), } } @@ -1023,7 +1029,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..359b4f1f50817 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -792,14 +792,15 @@ impl Result { } } - /// Unwraps 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, } } - /// Unwraps 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 { - /// Unwraps 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 /// @@ -964,7 +966,7 @@ impl Result { } } - /// Unwraps a result, yielding the content of an [`Ok`]. + /// Consumes a result, yielding the content of an [`Ok`]. /// /// # Panics /// @@ -994,13 +996,14 @@ impl Result { } impl Result { - /// Unwraps 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 ///