Skip to main content

HistoryRing

Struct HistoryRing 

Source
pub struct HistoryRing { /* private fields */ }
Expand description

LIFO ring buffer for yank/delete history (numbered registers 0-255).

§Example

use reovim_kernel::api::v1::*;

let mut ring = HistoryRing::new();
ring.push(RegisterContent::characterwise("first"));
ring.push(RegisterContent::characterwise("second"));

// Most recent is at index 0
assert_eq!(ring.get(0).map(|r| r.text.as_str()), Some("second"));
assert_eq!(ring.get(1).map(|r| r.text.as_str()), Some("first"));

Implementations§

Source§

impl HistoryRing

Source

pub const fn new() -> Self

Create a new history ring with default capacity (256).

Source

pub fn with_capacity(capacity: usize) -> Self

Create a history ring with custom capacity.

Source

pub fn push(&mut self, content: RegisterContent)

Push content to the front of the history.

The new entry becomes register 0. If the ring is full, the oldest entry (register 9) is discarded.

Source

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

Get an entry by index (0 = most recent).

Source

pub fn get_by_index(&self, index: u8) -> Option<&RegisterContent>

Get an entry by u8 index (0 = most recent).

This is the typed accessor for Register::History(u8). Returns None if the index is beyond the current history length.

Source

pub fn get_numbered(&self, n: char) -> Option<RegisterContent>

Get an entry by numbered register character (‘0’-‘9’).

Returns None if the character is not a digit or the index is beyond the current history length.

Source

pub fn len(&self) -> usize

Get the number of entries currently in the ring.

Source

pub fn is_empty(&self) -> bool

Check if the ring is empty.

Source

pub const fn capacity(&self) -> usize

Get the maximum capacity of the ring.

Source

pub fn iter(&self) -> impl Iterator<Item = &RegisterContent>

Iterate over entries in order (most recent first).

Source

pub fn clear(&mut self)

Clear all entries.

Trait Implementations§

Source§

impl Clone for HistoryRing

Source§

fn clone(&self) -> HistoryRing

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HistoryRing

Source§

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

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

impl Default for HistoryRing

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.