rustyline::history

Struct 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

Source§

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

Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

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>,

Source§

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>,

Source§

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.