From 28996db803b958b235f5f3e95bc1762955de8a05 Mon Sep 17 00:00:00 2001 From: Hunter Praska Date: Sun, 18 Jun 2017 13:07:09 -0500 Subject: Rename option::Missing to NoneError --- src/libcore/option.rs | 15 +++++++++------ src/libcore/tests/option.rs | 6 +++--- src/libcore/tests/result.rs | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 0c3339590db..980ea551f08 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1124,25 +1124,28 @@ impl> FromIterator> for Option { } } -/// The equivalent of `Option::None` for a `Result::Err`. +/// The error type that results from applying the try operator (`?`) to a `None` value. If you wish +/// to allow `x?` (where `x` is an `Option`) to be converted into your error type, you can +/// implement `impl From` for `YourErrorType`. In that case, `x?` within a function that +/// returns `Result<_, YourErrorType>` will translate a `None` value into an `Err` result. #[unstable(feature = "try_trait", issue = "42327")] #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] -pub struct Missing; +pub struct NoneError; #[unstable(feature = "try_trait", issue = "42327")] impl ops::Try for Option { type Ok = T; - type Error = Missing; + type Error = NoneError; - fn into_result(self) -> Result { - self.ok_or(Missing) + fn into_result(self) -> Result { + self.ok_or(NoneError) } fn from_ok(v: T) -> Self { Some(v) } - fn from_error(_: Missing) -> Self { + fn from_error(_: NoneError) -> Self { None } } diff --git a/src/libcore/tests/option.rs b/src/libcore/tests/option.rs index e2907e1dd89..22109e28edd 100644 --- a/src/libcore/tests/option.rs +++ b/src/libcore/tests/option.rs @@ -285,15 +285,15 @@ fn test_try() { } assert_eq!(try_option_none(), None); - fn try_option_ok() -> Result { + fn try_option_ok() -> Result { let val = Some(1)?; Ok(val) } assert_eq!(try_option_ok(), Ok(1)); - fn try_option_err() -> Result { + fn try_option_err() -> Result { let val = None?; Ok(val) } - assert_eq!(try_option_err(), Err(Missing)); + assert_eq!(try_option_err(), Err(NoneError)); } diff --git a/src/libcore/tests/result.rs b/src/libcore/tests/result.rs index 37264980dc7..ce41bde8342 100644 --- a/src/libcore/tests/result.rs +++ b/src/libcore/tests/result.rs @@ -214,7 +214,7 @@ fn test_try() { assert_eq!(try_result_some(), Some(1)); fn try_result_none() -> Option { - let val = Err(Missing)?; + let val = Err(NoneError)?; Some(val) } assert_eq!(try_result_none(), None); -- cgit 1.4.1-3-g733a5