Skip to content

Commit 28996db

Browse files
huntiepnikomatsakis
authored andcommitted
Rename option::Missing to NoneError
1 parent 8f63e8d commit 28996db

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/libcore/option.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1124,25 +1124,28 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
11241124
}
11251125
}
11261126

1127-
/// The equivalent of `Option::None` for a `Result::Err`.
1127+
/// The error type that results from applying the try operator (`?`) to a `None` value. If you wish
1128+
/// to allow `x?` (where `x` is an `Option<T>`) to be converted into your error type, you can
1129+
/// implement `impl From<NoneError>` for `YourErrorType`. In that case, `x?` within a function that
1130+
/// returns `Result<_, YourErrorType>` will translate a `None` value into an `Err` result.
11281131
#[unstable(feature = "try_trait", issue = "42327")]
11291132
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
1130-
pub struct Missing;
1133+
pub struct NoneError;
11311134

11321135
#[unstable(feature = "try_trait", issue = "42327")]
11331136
impl<T> ops::Try for Option<T> {
11341137
type Ok = T;
1135-
type Error = Missing;
1138+
type Error = NoneError;
11361139

1137-
fn into_result(self) -> Result<T, Missing> {
1138-
self.ok_or(Missing)
1140+
fn into_result(self) -> Result<T, NoneError> {
1141+
self.ok_or(NoneError)
11391142
}
11401143

11411144
fn from_ok(v: T) -> Self {
11421145
Some(v)
11431146
}
11441147

1145-
fn from_error(_: Missing) -> Self {
1148+
fn from_error(_: NoneError) -> Self {
11461149
None
11471150
}
11481151
}

src/libcore/tests/option.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ fn test_try() {
285285
}
286286
assert_eq!(try_option_none(), None);
287287

288-
fn try_option_ok() -> Result<u8, Missing> {
288+
fn try_option_ok() -> Result<u8, NoneError> {
289289
let val = Some(1)?;
290290
Ok(val)
291291
}
292292
assert_eq!(try_option_ok(), Ok(1));
293293

294-
fn try_option_err() -> Result<u8, Missing> {
294+
fn try_option_err() -> Result<u8, NoneError> {
295295
let val = None?;
296296
Ok(val)
297297
}
298-
assert_eq!(try_option_err(), Err(Missing));
298+
assert_eq!(try_option_err(), Err(NoneError));
299299
}

src/libcore/tests/result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn test_try() {
214214
assert_eq!(try_result_some(), Some(1));
215215

216216
fn try_result_none() -> Option<u8> {
217-
let val = Err(Missing)?;
217+
let val = Err(NoneError)?;
218218
Some(val)
219219
}
220220
assert_eq!(try_result_none(), None);

0 commit comments

Comments
 (0)