more idiomatic

This commit is contained in:
Sander Hautvast 2022-01-26 19:36:28 +01:00
parent 4319534b6b
commit 45389910ac

View file

@ -31,17 +31,13 @@ impl List {
}
pub fn pop(&mut self) -> Option<i32> {
let result;
match std::mem::replace(&mut self.head, Link::Empty) {
Link::Empty => {
result = None;
}
Link::Empty => None,
Link::More(node) => {
result = Some(node.elem);
self.head = node.next;
Some(node.elem)
}
};
result
}
}
}