[][src]Struct gapbuf::Slice

pub struct Slice<T> { /* fields omitted */ }

Sub-range of GapBuffer. Slice define common method for GapBuffer, Range, RangeMut.

Implementations

impl<T> Slice<T>[src]

pub fn empty() -> Self[src]

Construct a new, empty Slice.

pub fn len(&self) -> usize[src]

Returns the number of elements in the GapBuffer.

pub fn is_empty(&self) -> bool[src]

Returns true if the GapBuffer contains no elements.

pub fn get(&self, index: usize) -> Option<&T>[src]

Returns a reference to an element at index or None if out of bounds.

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>[src]

Returns a mutable reference to an element at index or None if out of bounds.

pub fn swap(&mut self, a: usize, b: usize)[src]

Swaps two elements in the GapBuffer.

Arguments

  • a - The index of the first element
  • b - The index of the second element

Panics

Panics if a >= self.len() or b >= self.len().

pub fn range(&self, range: impl RangeBounds<usize>) -> Range<'_, T>[src]

Return a immutable sub-range of this Slice.

Panics

Panics if range is out of bounds.

Examples

use gapbuf::gap_buffer;

let buf = gap_buffer![1, 2, 3, 4, 5];

let r1 = buf.range(1..);
assert_eq!(r1, [2, 3, 4, 5]);

let r2 = r1.range(1..3);
assert_eq!(r2, [3, 4]);

pub fn range_mut(&mut self, range: impl RangeBounds<usize>) -> RangeMut<'_, T>[src]

Return a mutable sub-range of this Slice.

Panics

Panics if range is out of bounds.

Examples

use gapbuf::gap_buffer;

let mut buf = gap_buffer![1, 2, 3, 4, 5];
{
    let mut r = buf.range_mut(1..);
    assert_eq!(r, [2, 3, 4, 5]);
    r[0] = 0;
}
assert_eq!(buf, [1, 0, 3, 4, 5]);

pub fn as_slices(&self) -> (&[T], &[T])[src]

Returns a pair of slices. First slice is before gap. Second slice is after gap.

Examples

use gapbuf::gap_buffer;

let mut buf = gap_buffer![1, 2, 3, 4, 5];
buf.set_gap(2);
let (s1, s2) = buf.as_slices();
assert_eq!(s1, [1, 2]);
assert_eq!(s2, [3, 4, 5]);

pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])[src]

Returns a pair of slices. First slice is before gap. Second slice is after gap.

Examples

use gapbuf::gap_buffer;

let mut buf = gap_buffer![1, 2, 3, 4, 5];
buf.set_gap(2);
{
    let (mut s1, mut s2) = buf.as_mut_slices();
    s1[0] = 10;
    s2[0] = 11;
}
assert_eq!(buf, [10, 2, 11, 4, 5]);

pub fn iter(&self) -> Iter<'_, T>[src]

Returns an iterator over the Slice.

pub fn iter_mut(&mut self) -> IterMut<'_, T>[src]

Returns an iterator that allows modifying each value.

Trait Implementations

impl<T> Debug for Slice<T> where
    T: Debug
[src]

impl<T: Eq> Eq for Slice<T>[src]

impl<T: Hash> Hash for Slice<T>[src]

impl<T> Index<usize> for Slice<T>[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<usize> for Slice<T>[src]

impl<'a, T> IntoIterator for &'a Slice<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T> IntoIterator for &'a mut Slice<T>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<T: Ord> Ord for Slice<T>[src]

impl<T, S> PartialEq<S> for Slice<T> where
    T: PartialEq,
    S: ?Sized,
    &'b S: IntoIterator<Item = &'b T>, 
[src]

impl<T, S> PartialOrd<S> for Slice<T> where
    T: PartialOrd,
    S: ?Sized,
    &'b S: IntoIterator<Item = &'b T>, 
[src]

impl<T: Send> Send for Slice<T>[src]

impl<T: Sync> Sync for Slice<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Slice<T> where
    T: RefUnwindSafe

impl<T> Unpin for Slice<T>

impl<T> UnwindSafe for Slice<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.