pub struct Slice<T> { /* private fields */ }
Expand description
Implementations
sourceimpl<T> Slice<T>
impl<T> Slice<T>
sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Returns a reference to an element at index or None if out of bounds.
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
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.
sourcepub fn range(&self, range: impl RangeBounds<usize>) -> Range<'_, T>
pub fn range(&self, range: impl RangeBounds<usize>) -> Range<'_, T>
sourcepub fn range_mut(&mut self, range: impl RangeBounds<usize>) -> RangeMut<'_, T>
pub fn range_mut(&mut self, range: impl RangeBounds<usize>) -> RangeMut<'_, T>
sourcepub fn as_slices(&self) -> (&[T], &[T])
pub fn as_slices(&self) -> (&[T], &[T])
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]);
sourcepub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
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
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]);
Trait Implementations
sourceimpl<'a, T> IntoIterator for &'a Slice<T>
impl<'a, T> IntoIterator for &'a Slice<T>
sourceimpl<'a, T> IntoIterator for &'a mut Slice<T>
impl<'a, T> IntoIterator for &'a mut Slice<T>
sourceimpl<T: Ord> Ord for Slice<T>
impl<T: Ord> Ord for Slice<T>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T, S> PartialEq<S> for Slice<T> where
T: PartialEq,
S: ?Sized,
for<'b> &'b S: IntoIterator<Item = &'b T>,
impl<T, S> PartialEq<S> for Slice<T> where
T: PartialEq,
S: ?Sized,
for<'b> &'b S: IntoIterator<Item = &'b T>,
sourceimpl<T, S> PartialOrd<S> for Slice<T> where
T: PartialOrd,
S: ?Sized,
for<'b> &'b S: IntoIterator<Item = &'b T>,
impl<T, S> PartialOrd<S> for Slice<T> where
T: PartialOrd,
S: ?Sized,
for<'b> &'b S: IntoIterator<Item = &'b T>,
sourcefn partial_cmp(&self, other: &S) -> Option<Ordering>
fn partial_cmp(&self, other: &S) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
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
impl<T: Eq> Eq for Slice<T>
impl<T: Send> Send for Slice<T>
impl<T: Sync> Sync for Slice<T>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more