Struct term_basics_linux::InputHistory
source · pub struct InputHistory { /* private fields */ }
Expand description
A struct that holds information about a history of typed input’s but the user.
Implementations
sourceimpl InputHistory
impl InputHistory
sourcepub fn new(maxlen: usize) -> Self
pub fn new(maxlen: usize) -> Self
Make a new InputHistory with a certain maximum capacity.
Example
use term_basics_linux as tbl;
let mut his = tbl::InputHistory::new(10);
let x = tbl::input_field_scrollable(&mut his);
sourcepub fn add(&mut self, string: &str)
pub fn add(&mut self, string: &str)
Adds an element to the history. 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::InputHistory::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);
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::InputHistory::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 InputHistory
impl Send for InputHistory
impl Sync for InputHistory
impl Unpin for InputHistory
impl UnwindSafe for InputHistory
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more