Skip to content

Commit 76e0e26

Browse files
committed
auto merge of #12888 : aochagavia/rust/Fix-comment, r=alexcrichton
The old comment of as_mut_slice() did not describe the function correctly. The new one does. Also refactored option::iter() and option::mut_iter() to use as_ref() and as_mut() instead of match.
2 parents 26fdfa1 + a7d3637 commit 76e0e26

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/libstd/option.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<T> Option<T> {
104104
}
105105
}
106106

107-
/// Convert from `Option<T>` to `&[T]` (without copying)
107+
/// Convert from `Option<T>` to `&mut [T]` (without copying)
108108
#[inline]
109109
pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] {
110110
match *self {
@@ -211,19 +211,13 @@ impl<T> Option<T> {
211211
/// Return an iterator over the possibly contained value
212212
#[inline]
213213
pub fn iter<'r>(&'r self) -> Item<&'r T> {
214-
match *self {
215-
Some(ref x) => Item{opt: Some(x)},
216-
None => Item{opt: None}
217-
}
214+
Item{opt: self.as_ref()}
218215
}
219216

220217
/// Return a mutable iterator over the possibly contained value
221218
#[inline]
222219
pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> {
223-
match *self {
224-
Some(ref mut x) => Item{opt: Some(x)},
225-
None => Item{opt: None}
226-
}
220+
Item{opt: self.as_mut()}
227221
}
228222

229223
/// Return a consuming iterator over the possibly contained value

0 commit comments

Comments
 (0)