Struct reedline::FileBackedHistory

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

Stateful history that allows up/down-arrow browsing with an internal cursor.

Can optionally be associated with a newline separated history file using the FileBackedHistory::with_file() constructor. Similar to bash’s behavior without HISTTIMEFORMAT. (See https://www.gnu.org/software/bash/manual/html_node/Bash-History-Facilities.html) If the history is associated to a file all new changes within a given history capacity will be written to disk when History is dropped.

Implementations§

source§

impl FileBackedHistory

source

pub fn new(capacity: usize) -> Result<Self>

Creates a new in-memory history that remembers n <= capacity elements

source

pub fn with_file(capacity: usize, file: PathBuf) -> Result<Self>

Creates a new history with an associated history file.

History file format: commands separated by new lines. If file exists file will be read otherwise empty file will be created.

Side effects: creates all nested directories to the file

Trait Implementations§

source§

impl Debug for FileBackedHistory

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for FileBackedHistory

source§

fn default() -> Self

Creates an in-memory History with a maximal capacity of HISTORY_SIZE.

To create a History that is synchronized with a file use FileBackedHistory::with_file()

§Panics

If HISTORY_SIZE == usize::MAX

source§

impl Drop for FileBackedHistory

source§

fn drop(&mut self)

On drop the content of the History will be written to the file if specified via FileBackedHistory::with_file().

source§

impl History for FileBackedHistory

source§

fn save(&mut self, h: HistoryItem) -> Result<HistoryItem>

only saves a value if it’s different than the last value

source§

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

Writes unwritten history contents to disk.

If file would exceed capacity truncates the oldest entries.

source§

fn load(&self, id: HistoryItemId) -> Result<HistoryItem>

load a history item by its id
source§

fn count(&self, query: SearchQuery) -> Result<i64>

retrieves the next unused session id count the results of a query
source§

fn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>>

return the results of a query
source§

fn update( &mut self, _id: HistoryItemId, _updater: &dyn Fn(HistoryItem) -> HistoryItem ) -> Result<()>

update an item atomically
source§

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

delete all history items
source§

fn delete(&mut self, _h: HistoryItemId) -> Result<()>

remove an item from this history
source§

fn session(&self) -> Option<HistorySessionId>

get the history session id
source§

fn count_all(&self) -> Result<i64>

return the total number of history items

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.