From 7681cf62e3d7e5dedb4bff455cd4fe8f7340d422 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 14 Jul 2013 22:35:27 +0200 Subject: [PATCH] dlist: Simplify by using Option::{map, map_mut} These methods were fixed or just added so they can now be used. --- src/libextra/dlist.rs | 17 ++++------------- 1 file 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 Mutable for DList { impl Deque for DList { /// 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