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.

SearchDirection is useful only for implementations without direct indexing.

Errors

Will return Err if history entry cannot be retrieved

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 / ...).

Errors

Will return Err if entry cannot be persisted

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 / ...).

Errors

Will return Err if entry cannot be persisted

fn len(&self) -> usize

Return the number of entries in the history.

fn is_empty(&self) -> bool

Return 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 len elements if the new history length value is smaller than the amount of items already inside the history.

Like stifle_history.

Errors

Will return Err if the size cannot be changed

fn ignore_dups(&mut self, yes: bool) -> Result<()>

Ignore consecutive duplicates

Errors

Will return Err if this setting cannot be changed

fn 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 Err if an IO error occurs

fn append(&mut self, path: &Path) -> Result<()>

Append new entries in the specified file.

Errors

Will return Err if an IO error occurs

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.

fn clear(&mut self) -> Result<()>

Clear in-memory history

Errors

Will return Err if an IO error occurs

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.

Errors

Will return Err if an IO error occurs

fn starts_with(&self, term: &str, start: usize, dir: SearchDirection) -> Result<Option<SearchResult<'_>>>

Anchored search

Errors

Will return Err if an IO error occurs

Implementors