Skip to content

Commit 7681cf6

Browse files
author
blake2-ppc
committed
dlist: Simplify by using Option::{map, map_mut}
These methods were fixed or just added so they can now be used.
1 parent 9ccf443 commit 7681cf6

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/libextra/dlist.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,31 +122,22 @@ impl<T> Mutable for DList<T> {
122122
impl<T> Deque<T> for DList<T> {
123123
/// Provide a reference to the front element, or None if the list is empty
124124
fn front<'a>(&'a self) -> Option<&'a T> {
125-
self.list_head.chain_ref(|x| Some(&x.value))
125+
self.list_head.map(|head| &head.value)
126126
}
127127

128128
/// Provide a mutable reference to the front element, or None if the list is empty
129129
fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
130-
match self.list_head {
131-
None => None,
132-
Some(ref mut head) => Some(&mut head.value),
133-
}
130+
self.list_head.map_mut(|head| &mut head.value)
134131
}
135132

136133
/// Provide a reference to the back element, or None if the list is empty
137134
fn back<'a>(&'a self) -> Option<&'a T> {
138-
match self.list_tail.resolve_immut() {
139-
None => None,
140-
Some(tail) => Some(&tail.value),
141-
}
135+
self.list_tail.resolve_immut().map(|tail| &tail.value)
142136
}
143137

144138
/// Provide a mutable reference to the back element, or None if the list is empty
145139
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
146-
match self.list_tail.resolve() {
147-
None => None,
148-
Some(tail) => Some(&mut tail.value),
149-
}
140+
self.list_tail.resolve().map_mut(|tail| &mut tail.value)
150141
}
151142

152143
/// Add an element last in the list

0 commit comments

Comments
 (0)