mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-27 19:26:09 +00:00
Add SelectView.get_item_mut
This commit is contained in:
parent
4dc403df78
commit
d3fadc7c3c
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user