Struct rustyline::history::History

source ·
pub struct History { /* private fields */ }
Expand description

Current state of the history.

Implementations§

source§

impl History

source

pub fn new() -> History

source

pub fn with_config(config: Config) -> History

source

pub fn get(&self, index: usize) -> Option<&String>

Return the history entry at position index, starting from 0.

source

pub fn last(&self) -> Option<&String>

Return the last history entry (i.e. previous command)

source

pub fn add<S: AsRef<str> + Into<String>>(&mut self, line: S) -> bool

Add a new entry in the history.

source

pub fn len(&self) -> usize

Return the number of entries in the history.

source

pub fn is_empty(&self) -> bool

Return true if the history has no entry.

source

pub fn set_max_len(&mut self, len: usize)

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](http://cnswww.cns.cwru. edu/php/chet/readline/history.html#IDX11).

source

pub fn save<P: AsRef<Path> + ?Sized>(&self, path: &P) -> Result<()>

Save the history in the specified file.

source

pub fn load<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()>

Load the history from the specified file.

§Errors

Will return Err if path does not already exist or could not be read.

source

pub fn clear(&mut self)

Clear history

source

pub fn search(&self, term: &str, start: usize, dir: Direction) -> Option<usize>

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.

source

pub fn starts_with( &self, term: &str, start: usize, dir: Direction ) -> Option<usize>

Anchored search

source

pub fn iter(&self) -> Iter<'_>

Return a forward iterator.

Trait Implementations§

source§

impl Default for History

source§

fn default() -> History

Returns the “default value” for a type. Read more
source§

impl Index<usize> for History

§

type Output = String

The returned type after indexing.
source§

fn index(&self, index: usize) -> &String

Performs the indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a History

§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
§

type Item = &'a String

The type of the elements being iterated over.
source§

fn into_iter(self) -> Iter<'a>

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.