more idiomatic with closure
This commit is contained in:
parent
beb5272b61
commit
0cf2b5c247
1 changed files with 8 additions and 11 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -35,13 +35,10 @@ impl <T> List<T> {
|
|||
}
|
||||
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
match self.head.take() {
|
||||
None => None,
|
||||
Some(node) => {
|
||||
self.head.take().map(|node| {
|
||||
self.head = node.next;
|
||||
Some(node.elem)
|
||||
}
|
||||
}
|
||||
node.elem
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +51,6 @@ mod tests {
|
|||
fn test() {
|
||||
let mut list = List::new();
|
||||
list.push(42);
|
||||
println!("{:?}", list);
|
||||
assert_eq!(Some(42), list.pop());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue