Add SelectView.get_item_mut

This commit is contained in:
Tymoteusz Jankowski 2018-01-26 17:24:44 +01:00
parent 4dc403df78
commit d3fadc7c3c

View File

@ -228,6 +228,21 @@ impl<T: 'static> SelectView<T> {
self.items.get(i).map(|item| (item.label.as_ref(), &*item.value)) self.items.get(i).map(|item| (item.label.as_ref(), &*item.value))
} }
/// Gets a mut item at given idx or None.
pub fn get_item_mut(&mut self, i: usize) -> Option<(&mut String, &mut T)> {
if i >= self.items.len() {
None
} else {
let item = &mut self.items[i];
if let Some(t) = Rc::get_mut(&mut item.value) {
let label = &mut item.label;
Some((label, t))
} else {
None
}
}
}
/// Removes an item from the list. /// Removes an item from the list.
pub fn remove_item(&mut self, id: usize) { pub fn remove_item(&mut self, id: usize) {
self.items.remove(id); self.items.remove(id);