pub trait History {
Show 14 methods
// Required methods
fn get(
&self,
index: usize,
dir: SearchDirection,
) -> Result<Option<SearchResult<'_>>>;
fn add(&mut self, line: &str) -> Result<bool>;
fn add_owned(&mut self, line: String) -> Result<bool>;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn set_max_len(&mut self, len: usize) -> Result<()>;
fn ignore_dups(&mut self, yes: bool) -> Result<()>;
fn ignore_space(&mut self, yes: bool);
fn save(&mut self, path: &Path) -> Result<()>;
fn append(&mut self, path: &Path) -> Result<()>;
fn load(&mut self, path: &Path) -> Result<()>;
fn clear(&mut self) -> Result<()>;
fn search(
&self,
term: &str,
start: usize,
dir: SearchDirection,
) -> Result<Option<SearchResult<'_>>>;
fn starts_with(
&self,
term: &str,
start: usize,
dir: SearchDirection,
) -> Result<Option<SearchResult<'_>>>;
}
Expand description
Interface for navigating/loading/storing history
Required Methods§
sourcefn get(
&self,
index: usize,
dir: SearchDirection,
) -> Result<Option<SearchResult<'_>>>
fn get( &self, index: usize, dir: SearchDirection, ) -> Result<Option<SearchResult<'_>>>
Return the history entry at position index
, starting from 0.
SearchDirection
is useful only for implementations without direct
indexing.
sourcefn add(&mut self, line: &str) -> Result<bool>
fn add(&mut self, line: &str) -> Result<bool>
Add a new entry in the history.
Return false if the line
has been ignored (blank line / duplicate /
…).
sourcefn add_owned(&mut self, line: String) -> Result<bool>
fn add_owned(&mut self, line: String) -> Result<bool>
Add a new entry in the history.
Return false if the line
has been ignored (blank line / duplicate /
…).
sourcefn set_max_len(&mut self, len: usize) -> Result<()>
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 len
elements if the new history length value is
smaller than the amount of items already inside the history.
Like stifle_history.
sourcefn ignore_dups(&mut self, yes: bool) -> Result<()>
fn ignore_dups(&mut self, yes: bool) -> Result<()>
Ignore consecutive duplicates
sourcefn ignore_space(&mut self, yes: bool)
fn ignore_space(&mut self, yes: bool)
Ignore lines which begin with a space or not
sourcefn load(&mut self, path: &Path) -> Result<()>
fn load(&mut self, path: &Path) -> Result<()>
Load the history from the specified file.
§Errors
Will return Err
if path does not already exist or could not be read.
sourcefn search(
&self,
term: &str,
start: usize,
dir: SearchDirection,
) -> Result<Option<SearchResult<'_>>>
fn 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 term
between [start, len -1] for
forward search
or between [0, start] for reverse search.
sourcefn starts_with(
&self,
term: &str,
start: usize,
dir: SearchDirection,
) -> Result<Option<SearchResult<'_>>>
fn starts_with( &self, term: &str, start: usize, dir: SearchDirection, ) -> Result<Option<SearchResult<'_>>>
Anchored search