You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
334 B
18 lines
334 B
5 years ago
|
pub trait TryRemove {
|
||
|
type Item;
|
||
|
fn try_remove(&mut self, index: usize) -> Option<Self::Item>;
|
||
|
}
|
||
|
|
||
|
impl<T> TryRemove for Vec<T> {
|
||
|
type Item = T;
|
||
|
|
||
|
fn try_remove(&mut self, index: usize) -> Option<T> {
|
||
|
if self.is_empty() {
|
||
|
None
|
||
|
} else {
|
||
|
Some(self.remove(index))
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|