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
impl FileBackedHistory
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new in-memory history that remembers n <= capacity elements
§Panics
If capacity == usize::MAX
Sourcepub fn with_file(capacity: usize, file: PathBuf) -> Result<Self>
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
impl Debug for FileBackedHistory
Source§impl Default for FileBackedHistory
impl Default for FileBackedHistory
Source§fn default() -> Self
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()
Source§impl Drop for FileBackedHistory
impl Drop for FileBackedHistory
Source§fn drop(&mut self)
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
impl History for FileBackedHistory
Source§fn save(&mut self, h: HistoryItem) -> Result<HistoryItem>
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<()>
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>
fn load(&self, id: HistoryItemId) -> Result<HistoryItem>
Source§fn count(&self, query: SearchQuery) -> Result<i64>
fn count(&self, query: SearchQuery) -> Result<i64>
Source§fn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>>
fn search(&self, query: SearchQuery) -> Result<Vec<HistoryItem>>
Source§fn update(
&mut self,
_id: HistoryItemId,
_updater: &dyn Fn(HistoryItem) -> HistoryItem,
) -> Result<()>
fn update( &mut self, _id: HistoryItemId, _updater: &dyn Fn(HistoryItem) -> HistoryItem, ) -> Result<()>
Source§fn session(&self) -> Option<HistorySessionId>
fn session(&self) -> Option<HistorySessionId>
Auto Trait Implementations§
impl Freeze for FileBackedHistory
impl RefUnwindSafe for FileBackedHistory
impl Send for FileBackedHistory
impl Sync for FileBackedHistory
impl Unpin for FileBackedHistory
impl UnwindSafe for FileBackedHistory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more