Trait History
pub trait History
Interface for navigating/loading/storing history
Required Methods
fn get(&self, index: usize, dir: SearchDirection) -> Result<Option<SearchResult<'_>>>Return the history entry at position
index, starting from 0.SearchDirectionis useful only for implementations without direct indexing.Errors
Will return
Errif history entry cannot be retrievedfn add(&mut self, line: &str) -> Result<bool>Add a new entry in the history.
Return false if the
linehas been ignored (blank line / duplicate / ...).Errors
Will return
Errif entry cannot be persistedfn add_owned(&mut self, line: String) -> Result<bool>Add a new entry in the history.
Return false if the
linehas been ignored (blank line / duplicate / ...).Errors
Will return
Errif entry cannot be persistedfn len(&self) -> usizeReturn the number of entries in the history.
fn is_empty(&self) -> boolReturn true if the history has no entry.
fn set_max_len(&mut self, len: usize) -> Result<()>Set the maximum length for the history. This function can be called even if there is already some history, the function will make sure to retain just the latest
lenelements if the new history length value is smaller than the amount of items already inside the history.Like stifle_history.
Errors
Will return
Errif the size cannot be changedfn ignore_dups(&mut self, yes: bool) -> Result<()>Ignore consecutive duplicates
Errors
Will return
Errif this setting cannot be changedfn ignore_space(&mut self, yes: bool)Ignore lines which begin with a space or not
fn save(&mut self, path: &Path) -> Result<()>Save the history in the specified file.
Errors
Will return
Errif an IO error occursfn append(&mut self, path: &Path) -> Result<()>Append new entries in the specified file.
Errors
Will return
Errif an IO error occursfn load(&mut self, path: &Path) -> Result<()>Load the history from the specified file.
Errors
Will return
Errif path does not already exist or could not be read.fn clear(&mut self) -> Result<()>Clear in-memory history
Errors
Will return
Errif an IO error occursfn search(&self, term: &str, start: usize, dir: SearchDirection) -> Result<Option<SearchResult<'_>>>Search history (start position inclusive [0, len-1]).
Return the absolute index of the nearest history entry that matches
term.Return None if no entry contains
termbetween [start, len -1] for forward search or between [0, start] for reverse search.Errors
Will return
Errif an IO error occursfn starts_with(&self, term: &str, start: usize, dir: SearchDirection) -> Result<Option<SearchResult<'_>>>Anchored search
Errors
Will return
Errif an IO error occurs
Implementors
impl History for FileHistoryimpl History for MemHistory