Struct GapBuffer

Source
pub struct GapBuffer<T> { /* private fields */ }
Expand description

A GapBuffer is a dynamic array which implements methods to shift the empty portion of the array around so that modifications can occur at any point in the array. It is optimized for data structures in which insertions and deletions tend to occur in sequence within the same area of the array, such as a buffer for a text editor.

Implementations§

Source§

impl<T> GapBuffer<T>

Source

pub fn new() -> GapBuffer<T>

Constructs an empty GapBuffer.

Source

pub fn with_capacity(n: usize) -> GapBuffer<T>

Constructs a GapBuffer with a given initial capacity.

Source

pub fn get(&self, i: usize) -> Option<&T>

Get a reference to the element at the index.

Source

pub fn get_mut(&mut self, i: usize) -> Option<&mut T>

Get a mutable reference to the element at the index.

Source

pub fn swap(&mut self, i: usize, j: usize)

Swap the elements at the index. i and j may be equal.

Panics if there is no element with either index.

Source

pub fn capacity(&self) -> usize

Get the capacity of the GapBuffer without expanding.

Source

pub fn reserve(&mut self, additional: usize)

Reserve at least this much additional space for the GapBuffer. The collection may reserve more space to avoid frequent reallocations.

Panics if the new capacity overflows uint.

Source

pub fn iter(&self) -> Items<'_, T>

Get an iterator of this GapBuffer.

Source

pub fn len(&self) -> usize

Get the length of the GapBuffer.

Source

pub fn is_empty(&self) -> bool

Is the GapBuffer empty?

Source

pub fn clear(&mut self)

Clears the buffer, removing all values.

Source

pub fn insert(&mut self, i: usize, t: T)

Insert a new T at a given index (the gap will be shifted to that index).

Panics if i is greater than VecDeque’s length.

Source

pub fn remove(&mut self, i: usize) -> Option<T>

Removes and returns the element at position i from the gap buffer. The gap will be shifted to just before the index. Returns None if i is out of bounds.

Trait Implementations§

Source§

impl<T: Clone> Clone for GapBuffer<T>

Source§

fn clone(&self) -> GapBuffer<T>

Returns a copy 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<T> Debug for GapBuffer<T>
where T: Debug,

Source§

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

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

impl<T: Default> Default for GapBuffer<T>

Source§

fn default() -> GapBuffer<T>

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

impl<A> Extend<A> for GapBuffer<A>

Source§

fn extend<T: IntoIterator<Item = A>>(&mut self, iterator: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<A> FromIterator<A> for GapBuffer<A>

Source§

fn from_iter<I: IntoIterator<Item = A>>(iterator: I) -> GapBuffer<A>

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for GapBuffer<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index<'a>(&'a self, index: usize) -> &'a T

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

impl<T> IndexMut<usize> for GapBuffer<T>

Source§

fn index_mut<'a>(&'a mut self, index: usize) -> &'a mut T

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

impl<A> Ord for GapBuffer<A>
where A: Ord,

Source§

fn cmp(&self, other: &GapBuffer<A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<A, B> PartialEq<GapBuffer<B>> for GapBuffer<A>
where A: PartialEq<B>,

Source§

fn eq(&self, other: &GapBuffer<B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A> PartialOrd for GapBuffer<A>
where A: PartialOrd,

Source§

fn partial_cmp(&self, other: &GapBuffer<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A> Eq for GapBuffer<A>
where A: Eq,

Auto Trait Implementations§

§

impl<T> Freeze for GapBuffer<T>

§

impl<T> RefUnwindSafe for GapBuffer<T>
where T: RefUnwindSafe,

§

impl<T> Send for GapBuffer<T>
where T: Send,

§

impl<T> Sync for GapBuffer<T>
where T: Sync,

§

impl<T> Unpin for GapBuffer<T>
where T: Unpin,

§

impl<T> UnwindSafe for GapBuffer<T>
where T: UnwindSafe,

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.