From dcf320a6394c712aaeca1cd39f054b11c129af97 Mon Sep 17 00:00:00 2001 From: aochagavia Date: Fri, 14 Mar 2014 16:32:04 +0100 Subject: [PATCH 1/2] Fixed comment of as_mut_slice (libstd/option.rs) The old comment did not describe the function correctly --- src/libstd/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 86f8c143a9e99..d315e8e3219d6 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -104,7 +104,7 @@ impl Option { } } - /// Convert from `Option` to `&[T]` (without copying) + /// Convert from `Option` to `&mut [T]` (without copying) #[inline] pub fn as_mut_slice<'r>(&'r mut self) -> &'r mut [T] { match *self { From a7d3637f6711cc96a5f6dc86772dba14fef1a013 Mon Sep 17 00:00:00 2001 From: aochagavia Date: Fri, 14 Mar 2014 17:29:47 +0100 Subject: [PATCH 2/2] Refactored iter and mut_iter Replaced match by self.as_ref() and self.as_mut() --- src/libstd/option.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libstd/option.rs b/src/libstd/option.rs index d315e8e3219d6..49d40605c268d 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -211,19 +211,13 @@ impl Option { /// Return an iterator over the possibly contained value #[inline] pub fn iter<'r>(&'r self) -> Item<&'r T> { - match *self { - Some(ref x) => Item{opt: Some(x)}, - None => Item{opt: None} - } + Item{opt: self.as_ref()} } /// Return a mutable iterator over the possibly contained value #[inline] pub fn mut_iter<'r>(&'r mut self) -> Item<&'r mut T> { - match *self { - Some(ref mut x) => Item{opt: Some(x)}, - None => Item{opt: None} - } + Item{opt: self.as_mut()} } /// Return a consuming iterator over the possibly contained value