Rename option::Missing to NoneError

This commit is contained in:
Hunter Praska 2017-06-18 13:07:09 -05:00 committed by Niko Matsakis
parent 8f63e8de46
commit 28996db803
3 changed files with 13 additions and 10 deletions

View File

@ -1124,25 +1124,28 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
}
}
/// 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<T>`) to be converted into your error type, you can
/// implement `impl From<NoneError>` 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<T> ops::Try for Option<T> {
type Ok = T;
type Error = Missing;
type Error = NoneError;
fn into_result(self) -> Result<T, Missing> {
self.ok_or(Missing)
fn into_result(self) -> Result<T, NoneError> {
self.ok_or(NoneError)
}
fn from_ok(v: T) -> Self {
Some(v)
}
fn from_error(_: Missing) -> Self {
fn from_error(_: NoneError) -> Self {
None
}
}

View File

@ -285,15 +285,15 @@ fn test_try() {
}
assert_eq!(try_option_none(), None);
fn try_option_ok() -> Result<u8, Missing> {
fn try_option_ok() -> Result<u8, NoneError> {
let val = Some(1)?;
Ok(val)
}
assert_eq!(try_option_ok(), Ok(1));
fn try_option_err() -> Result<u8, Missing> {
fn try_option_err() -> Result<u8, NoneError> {
let val = None?;
Ok(val)
}
assert_eq!(try_option_err(), Err(Missing));
assert_eq!(try_option_err(), Err(NoneError));
}

View File

@ -214,7 +214,7 @@ fn test_try() {
assert_eq!(try_result_some(), Some(1));
fn try_result_none() -> Option<u8> {
let val = Err(Missing)?;
let val = Err(NoneError)?;
Some(val)
}
assert_eq!(try_result_none(), None);