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

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

Implementations

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

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

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

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

Returns an iterator over the Slice.

Returns an iterator that allows modifying each value.

Trait Implementations

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

The returned type after indexing.

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

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

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

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

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

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.