Struct term_basics_linux::InputList
source · pub struct InputList { /* private fields */ }
Expand description
A struct that holds inputs available for the user to scroll through.
Implementations§
source§impl InputList
impl InputList
sourcepub fn new(maxlen: usize) -> Self
pub fn new(maxlen: usize) -> Self
Make a new InputList with a certain maximum capacity.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputList::new(10);
let x = tbl::input_field_scrollable(&mut his, true);
sourcepub fn add(&mut self, string: &str)
pub fn add(&mut self, string: &str)
Adds an element to the list. It will delete items if it’s length would grow past the max length. the oldest items will be removed.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputList::new(2);
his.add(&"0".to_string());
his.add(&"1".to_string());
his.add(&"2".to_string());
// only "1" and "2" will remain, as 0 is removed.
let _ = tbl::input_field_scrollable(&mut his, true);
sourcepub fn get_index(&self, index: i32) -> Option<&String>
pub fn get_index(&self, index: i32) -> Option<&String>
Returns the an Option of String, the element at the given index. The index wraps and you can query for negative indices as well as indices above the maximum length.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputList::new(3);
his.add(&"0".to_string());
his.add(&"1".to_string());
his.add(&"2".to_string());
println!("at -2: {:?}", his.get_index(-2)); // "1"
println!("at -1: {:?}", his.get_index(-1)); // "2"
println!("at 0: {:?}", his.get_index(0)); // "0"
println!("at 1: {:?}", his.get_index(1)); // "1"
println!("at 2: {:?}", his.get_index(2)); // "2"
println!("at 3: {:?}", his.get_index(3)); // "0"
println!("at 4: {:?}", his.get_index(4)); // "1"
Auto Trait Implementations§
impl RefUnwindSafe for InputList
impl Send for InputList
impl Sync for InputList
impl Unpin for InputList
impl UnwindSafe for InputList
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more