Trait History
trait History
Interface for navigating/loading/storing history
Required Methods
fn get(self: &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.fn add(self: &mut Self, line: &str) -> Result<bool>Add a new entry in the history.
Return false if the
linehas been ignored (blank line / duplicate / ...).fn add_owned(self: &mut Self, line: String) -> Result<bool>Add a new entry in the history.
Return false if the
linehas been ignored (blank line / duplicate / ...).fn len(self: &Self) -> usizeReturn the number of entries in the history.
fn is_empty(self: &Self) -> boolReturn true if the history has no entry.
fn set_max_len(self: &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.
fn ignore_dups(self: &mut Self, yes: bool) -> Result<()>Ignore consecutive duplicates
fn ignore_space(self: &mut Self, yes: bool)Ignore lines which begin with a space or not
fn save(self: &mut Self, path: &Path) -> Result<()>Save the history in the specified file.
fn append(self: &mut Self, path: &Path) -> Result<()>Append new entries in the specified file.
fn load(self: &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(self: &mut Self) -> Result<()>Clear in-memory history
fn search(self: &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.fn starts_with(self: &Self, term: &str, start: usize, dir: SearchDirection) -> Result<Option<SearchResult<'_>>>Anchored search
Implementors
impl History for MemHistoryimpl History for FileHistory