Struct gapbuf::Slice[][src]

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

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

Methods

impl<T> Slice<T>
[src]

Construct a new, empty Slice.

Returns the number of elements in the GapBuffer.

Returns true if the GapBuffer contains no elements.

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

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

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().

Return a immutable sub-range of this Slice.

Panics

Panics if range is out of bounds.

Examples

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]);

Return a mutable sub-range of this Slice.

Panics

Panics if range is out of bounds.

Examples

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]);

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

Examples

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]);

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

Examples

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]);

Returns an iterator over the Slice.

Returns an iterator that allows modifying each value.

Trait Implementations

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

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

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

Performs the mutable indexing (container[index]) operation.

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

Formats the value using the given formatter. Read more

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

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more