From 4dc403df780626b83dbe41a88fa6f66b1c3bce41 Mon Sep 17 00:00:00 2001 From: Tymoteusz Jankowski Date: Fri, 26 Jan 2018 13:25:19 +0100 Subject: [PATCH] Add SelectView.get_item --- src/views/select_view.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 2c6df29..9df0556 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -215,6 +215,19 @@ impl SelectView { self.items.push(Item::new(label.into(), value)); } + /// Gets an item at given idx or None. + /// + /// ``` + /// use cursive::Cursive; + /// use cursive::views::{SelectView, TextView}; + /// let select = SelectView::new() + /// .item("Short", 1); + /// assert_eq!(select.get_item(0), Some(("Short", &1))); + /// ``` + pub fn get_item(&self, i: usize) -> Option<(&str, &T)> { + self.items.get(i).map(|item| (item.label.as_ref(), &*item.value)) + } + /// Removes an item from the list. pub fn remove_item(&mut self, id: usize) { self.items.remove(id);