[][src]Struct gapbuf::RangeMut

pub struct RangeMut<'a, T: 'a> { /* fields omitted */ }

Mutable sub-range of GapBuffer.

This struct is created by Slice::range_mut.

Implementations

impl<'a, T: 'a> RangeMut<'a, T>[src]

pub fn empty() -> Self[src]

Construct a new, empty RangeMut.

Methods from Deref<Target = Slice<T>>

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<'a, T> Debug for RangeMut<'a, T> where
    T: Debug
[src]

impl<'a, T> Default for RangeMut<'a, T>[src]

impl<'a, T> Deref for RangeMut<'a, T>[src]

type Target = Slice<T>

The resulting type after dereferencing.

impl<'a, T> DerefMut for RangeMut<'a, T>[src]

impl<'a, T: Eq> Eq for RangeMut<'a, T>[src]

impl<'a, T: Hash + 'a> Hash for RangeMut<'a, T>[src]

impl<'a, T> Index<usize> for RangeMut<'a, T>[src]

type Output = T

The returned type after indexing.

impl<'a, T> IndexMut<usize> for RangeMut<'a, T>[src]

impl<'a, 'b, T> IntoIterator for &'a RangeMut<'b, 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 RangeMut<'a, 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<'a, T: Ord> Ord for RangeMut<'a, T>[src]

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

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

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for RangeMut<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for RangeMut<'a, T> where
    T: Send

impl<'a, T> Sync for RangeMut<'a, T> where
    T: Sync

impl<'a, T> Unpin for RangeMut<'a, T>

impl<'a, T> !UnwindSafe for RangeMut<'a, T>

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.