Rename option::Missing to NoneError
This commit is contained in:
parent
8f63e8de46
commit
28996db803
@ -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")]
|
#[unstable(feature = "try_trait", issue = "42327")]
|
||||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||||
pub struct Missing;
|
pub struct NoneError;
|
||||||
|
|
||||||
#[unstable(feature = "try_trait", issue = "42327")]
|
#[unstable(feature = "try_trait", issue = "42327")]
|
||||||
impl<T> ops::Try for Option<T> {
|
impl<T> ops::Try for Option<T> {
|
||||||
type Ok = T;
|
type Ok = T;
|
||||||
type Error = Missing;
|
type Error = NoneError;
|
||||||
|
|
||||||
fn into_result(self) -> Result<T, Missing> {
|
fn into_result(self) -> Result<T, NoneError> {
|
||||||
self.ok_or(Missing)
|
self.ok_or(NoneError)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_ok(v: T) -> Self {
|
fn from_ok(v: T) -> Self {
|
||||||
Some(v)
|
Some(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_error(_: Missing) -> Self {
|
fn from_error(_: NoneError) -> Self {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,15 +285,15 @@ fn test_try() {
|
|||||||
}
|
}
|
||||||
assert_eq!(try_option_none(), None);
|
assert_eq!(try_option_none(), None);
|
||||||
|
|
||||||
fn try_option_ok() -> Result<u8, Missing> {
|
fn try_option_ok() -> Result<u8, NoneError> {
|
||||||
let val = Some(1)?;
|
let val = Some(1)?;
|
||||||
Ok(val)
|
Ok(val)
|
||||||
}
|
}
|
||||||
assert_eq!(try_option_ok(), Ok(1));
|
assert_eq!(try_option_ok(), Ok(1));
|
||||||
|
|
||||||
fn try_option_err() -> Result<u8, Missing> {
|
fn try_option_err() -> Result<u8, NoneError> {
|
||||||
let val = None?;
|
let val = None?;
|
||||||
Ok(val)
|
Ok(val)
|
||||||
}
|
}
|
||||||
assert_eq!(try_option_err(), Err(Missing));
|
assert_eq!(try_option_err(), Err(NoneError));
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ fn test_try() {
|
|||||||
assert_eq!(try_result_some(), Some(1));
|
assert_eq!(try_result_some(), Some(1));
|
||||||
|
|
||||||
fn try_result_none() -> Option<u8> {
|
fn try_result_none() -> Option<u8> {
|
||||||
let val = Err(Missing)?;
|
let val = Err(NoneError)?;
|
||||||
Some(val)
|
Some(val)
|
||||||
}
|
}
|
||||||
assert_eq!(try_result_none(), None);
|
assert_eq!(try_result_none(), None);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user