diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 9df0556..1078fd3 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -228,6 +228,21 @@ impl SelectView { 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. pub fn remove_item(&mut self, id: usize) { self.items.remove(id);