simplify NeverEmptyVec::last, as suggested by @pickfire
This commit is contained in:
parent
9ccf49010c
commit
c957c10678
@ -18,17 +18,11 @@ impl<T> NeverEmptyVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn last(&self) -> &T {
|
pub fn last(&self) -> &T {
|
||||||
match self.rest.last() {
|
self.rest.last().unwrap_or(&self.first)
|
||||||
Some(v) => v,
|
|
||||||
None => &self.first,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_mut(&mut self) -> &mut T {
|
pub fn last_mut(&mut self) -> &mut T {
|
||||||
match self.rest.last_mut() {
|
self.rest.last_mut().unwrap_or(&mut self.first)
|
||||||
Some(v) => v,
|
|
||||||
None => &mut self.first,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, value: T) {
|
pub fn push(&mut self, value: T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user