diff options
| author | blake2-ppc <blake2-ppc> | 2013-07-14 22:35:27 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-07-14 22:59:15 +0200 |
| commit | 7681cf62e3d7e5dedb4bff455cd4fe8f7340d422 (patch) | |
| tree | 95d39ea476e2aba00c9dd478fca0f2ef89f2a390 | |
| parent | 9ccf443088c56bab91369c6633cfeb39de66d6de (diff) | |
| download | rust-7681cf62e3d7e5dedb4bff455cd4fe8f7340d422.tar.gz rust-7681cf62e3d7e5dedb4bff455cd4fe8f7340d422.zip | |
dlist: Simplify by using Option::{map, map_mut}
These methods were fixed or just added so they can now be used.
| -rw-r--r-- | src/libextra/dlist.rs | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 283a726988b..1731de2691e 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -122,31 +122,22 @@ impl<T> Mutable for DList<T> { impl<T> Deque<T> for DList<T> { /// Provide a reference to the front element, or None if the list is empty fn front<'a>(&'a self) -> Option<&'a T> { - self.list_head.chain_ref(|x| Some(&x.value)) + self.list_head.map(|head| &head.value) } /// Provide a mutable reference to the front element, or None if the list is empty fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> { - match self.list_head { - None => None, - Some(ref mut head) => Some(&mut head.value), - } + self.list_head.map_mut(|head| &mut head.value) } /// Provide a reference to the back element, or None if the list is empty fn back<'a>(&'a self) -> Option<&'a T> { - match self.list_tail.resolve_immut() { - None => None, - Some(tail) => Some(&tail.value), - } + self.list_tail.resolve_immut().map(|tail| &tail.value) } /// Provide a mutable reference to the back element, or None if the list is empty fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> { - match self.list_tail.resolve() { - None => None, - Some(tail) => Some(&mut tail.value), - } + self.list_tail.resolve().map_mut(|tail| &mut tail.value) } /// Add an element last in the list |
