Struct gapbuf::Slice [−][src]
pub struct Slice<T> { /* fields omitted */ }
Methods
impl<T> Slice<T>
[src]
impl<T> Slice<T>
pub fn empty() -> Self
[src]
pub fn empty() -> Self
Construct a new, empty Slice
.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of elements in the GapBuffer.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true if the GapBuffer contains no elements.
pub fn get(&self, index: usize) -> Option<&T>
[src]
pub fn get(&self, index: usize) -> Option<&T>
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]
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
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]
pub fn swap(&mut self, a: usize, b: usize)
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]
pub fn range(
&self,
range: impl RangeBounds<usize>
) -> Range<T>
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]);
pub fn range_mut(
&mut self,
range: impl RangeBounds<usize>
) -> RangeMut<T>
[src]
pub fn range_mut(
&mut self,
range: impl RangeBounds<usize>
) -> RangeMut<T>
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]);
pub fn as_slices(&self) -> (&[T], &[T])
[src]
pub fn as_slices(&self) -> (&[T], &[T])
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]);
pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
[src]
pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
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]);
pub fn iter(&self) -> Iter<T>
[src]
pub fn iter(&self) -> Iter<T>
Returns an iterator over the Slice.
pub fn iter_mut(&mut self) -> IterMut<T>
[src]
pub fn iter_mut(&mut self) -> IterMut<T>
Returns an iterator that allows modifying each value.
Trait Implementations
impl<T: Sync> Sync for Slice<T>
[src]
impl<T: Sync> Sync for Slice<T>
impl<T: Send> Send for Slice<T>
[src]
impl<T: Send> Send for Slice<T>
impl<T> Index<usize> for Slice<T>
[src]
impl<T> Index<usize> for Slice<T>
type Output = T
The returned type after indexing.
fn index(&self, index: usize) -> &T
[src]
fn index(&self, index: usize) -> &T
Performs the indexing (container[index]
) operation.
impl<T> IndexMut<usize> for Slice<T>
[src]
impl<T> IndexMut<usize> for Slice<T>
fn index_mut(&mut self, index: usize) -> &mut T
[src]
fn index_mut(&mut self, index: usize) -> &mut T
Performs the mutable indexing (container[index]
) operation.
impl<T> Debug for Slice<T> where
T: Debug,
[src]
impl<T> Debug for Slice<T> where
T: Debug,
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<T: Hash> Hash for Slice<T>
[src]
impl<T: Hash> Hash for Slice<T>
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
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]
impl<T, S> PartialEq<S> for Slice<T> where
T: PartialEq,
S: ?Sized,
&'b S: IntoIterator<Item = &'b T>,
fn eq(&self, other: &S) -> bool
[src]
fn eq(&self, other: &S) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<T: Eq> Eq for Slice<T>
[src]
impl<T: Eq> Eq for Slice<T>
impl<T, S> PartialOrd<S> for Slice<T> where
T: PartialOrd,
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>,
fn partial_cmp(&self, other: &S) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &S) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
fn ge(&self, other: &Rhs) -> bool
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]
impl<T: Ord> Ord for Slice<T>
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<'a, T> IntoIterator for &'a Slice<T>
[src]
impl<'a, T> IntoIterator for &'a Slice<T>
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?
fn into_iter(self) -> Iter<'a, T>
[src]
fn into_iter(self) -> Iter<'a, T>
Creates an iterator from a value. Read more
impl<'a, T> IntoIterator for &'a mut Slice<T>
[src]
impl<'a, T> IntoIterator for &'a mut Slice<T>