Struct strided::MutStride
[−]
[src]
#[repr(C)]pub struct MutStride<'a, T: 'a> { /* fields omitted */ }
A mutable strided slice. This is equivalent to &mut [T]
, that
only refers to every n
th T
.
This can be viewed as an immutable strided slice via the Deref
implementation, and so many methods are available through that
type.
Many functions in this API take self
and consume it. The
reborrow
method is a key part of ensuring that ownership doesn't
disappear completely: it converts a reference
&'b mut MutStride<'a, T>
into a MutStride<'b, T>
, that is, gives a
by-value slice with a shorter lifetime. This can then be passed
directly into the functions that consume self
without losing
control of the original slice.
Methods
impl<'a, T> Stride<'a, T>
[src]
fn new(x: &'a mut [T]) -> Stride<'a, T>
Creates a new strided slice directly from a conventional slice. The return value has stride 1.
fn len(&self) -> usize
Returns the number of elements accessible in self
.
fn stride(&self) -> usize
Returns the offset between successive elements of self
as a
count of elements, not bytes.
fn as_mut_ptr(&mut self) -> *mut T
Returns a pointer to the first element of this strided slice.
NB. one must be careful since only every self.stride()
th
element is guaranteed to have unique access via this object;
the others may be under the control of some other strided
slice.
fn reborrow<'b>(&'b mut self) -> Stride<'b, T>
Creates a temporary copy of this strided slice.
This is an explicit form of the reborrowing the compiler does
implicitly for conventional &mut
pointers. This is designed
to allow the by-value self
methods to be used without losing
access to the slice.
fn substrides2_mut(self) -> (Stride<'a, T>, Stride<'a, T>)
Breaks this strided slice into two strided slices pointing to alternate elements.
That is, it doubles the stride and (approximately) halves the
length. A slice pointing to values [1, 2, 3, 4, 5]
becomes
two slices [1, 3, 5]
and [2, 4]
. This is guaranteed to
succeed even for mismatched lengths, and even if self
has
only zero or one elements.
fn substrides_mut(self, n: usize) -> Substrides<'a, T>
Returns an iterator over n
strided subslices of self
each
pointing to every n
th element, starting at successive
offsets.
Calling substrides(3)
on a slice pointing to [1, 2, 3, 4, 5, 6, 7]
will yield, in turn, [1, 4, 7]
, [2, 5]
and finally
[3, 6]
. Like with split2
this is guaranteed to succeed
(return n
strided slices) even if self
has fewer than n
elements.
fn get_mut<'b>(&'b mut self, n: usize) -> Option<&'b mut T>
Returns a reference to the n
th element of self
, or None
if n
is out-of-bounds.
fn iter_mut<'b>(&'b mut self) -> MutItems<'b, T>
Returns an iterator over references to each successive element
of self
.
See also into_iter
which gives the references the maximum
possible lifetime at the expense of consume the slice.
fn into_iter(self) -> MutItems<'a, T>
Returns an iterator over reference to each successive element
of self
, with the maximum possible lifetime.
See also iter_mut
which avoids consuming self
at the
expense of shorter lifetimes.
fn slice_mut(self, from: usize, to: usize) -> Stride<'a, T>
Returns a strided slice containing only the elements from
indices from
(inclusive) to to
(exclusive).
Panic
Panics if from > to
or if to > self.len()
.
fn slice_from_mut(self, from: usize) -> Stride<'a, T>
Returns a strided slice containing only the elements from
index from
(inclusive).
Panic
Panics if from > self.len()
.
fn slice_to_mut(self, to: usize) -> Stride<'a, T>
Returns a strided slice containing only the elements to
index to
(exclusive).
Panic
Panics if to > self.len()
.
fn split_at_mut(self, idx: usize) -> (Stride<'a, T>, Stride<'a, T>)
Returns two strided slices, the first with elements up to
idx
(exclusive) and the second with elements from idx
.
This is semantically equivalent to (self.slice_to(idx), self.slice_from(idx))
.
Panic
Panics if idx > self.len()
.
Methods from Deref<Target = Stride<'a, T>>
fn len(&self) -> usize
Returns the number of elements accessible in self
.
fn stride(&self) -> usize
Returns the offset between successive elements of self
as a
count of elements, not bytes.
fn as_ptr(&self) -> *const T
Returns a pointer to the first element of this strided slice.
NB. one must be careful since only every self.stride()
th
element is guaranteed to have unique access via this object;
the others may be under the control of some other strided
slice.
fn substrides2(&self) -> (Stride<'a, T>, Stride<'a, T>)
Breaks this strided slice into two strided slices pointing to alternate elements.
That is, it doubles the stride and (approximately) halves the
length. A slice pointing to values [1, 2, 3, 4, 5]
becomes
two slices [1, 3, 5]
and [2, 4]
. This is guaranteed to
succeed even if self.len()
is odd, and even if self
has only zero or one elements.
fn substrides(&self, n: usize) -> Substrides<'a, T>
Returns an iterator over n
strided subslices of self
each
pointing to every n
th element, starting at successive
offsets.
Calling substrides(3)
on a slice pointing to [1, 2, 3, 4, 5, 6, 7]
will yield, in turn, [1, 4, 7]
, [2, 5]
and finally
[3, 6]
. Like with split2
this is guaranteed to succeed
(return n
strided slices) even if self
has fewer than n
elements and if self.len()
is not a multiple of n
.
fn get(&self, n: usize) -> Option<&'a T>
Returns a reference to the n
th element of self
, or None
if n
is out-of-bounds.
fn iter(&self) -> Items<'a, T>
Returns an iterator over references to each successive element
of self
.
Unlike MutStrides
, this can return references with the
maximum lifetime without consuming self
and so an
into_iter
equivalent is unnecessary.
fn slice(&self, from: usize, to: usize) -> Stride<'a, T>
Returns a strided slice containing only the elements from
indices from
(inclusive) to to
(exclusive).
Panic
Panics if from > to
or if to > self.len()
.
fn slice_from(&self, from: usize) -> Stride<'a, T>
Returns a strided slice containing only the elements from
index from
(inclusive).
Panic
Panics if from > self.len()
.
fn slice_to(&self, to: usize) -> Stride<'a, T>
Returns a strided slice containing only the elements to
index to
(exclusive).
Panic
Panics if to > self.len()
.
fn split_at(&self, idx: usize) -> (Stride<'a, T>, Stride<'a, T>)
Returns two strided slices, the first with elements up to
idx
(exclusive) and the second with elements from idx
.
This is semantically equivalent to (self.slice_to(idx), self.slice_from(idx))
.
Panic
Panics if idx > self.len()
.
Trait Implementations
impl<'a, T: PartialEq + 'a> PartialEq for Stride<'a, T>
[src]
fn eq(&self, __arg_0: &Stride<'a, T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Stride<'a, T>) -> bool
This method tests for !=
.
impl<'a, T: Eq + 'a> Eq for Stride<'a, T>
[src]
impl<'a, T: PartialOrd + 'a> PartialOrd for Stride<'a, T>
[src]
fn partial_cmp(&self, __arg_0: &Stride<'a, T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Stride<'a, T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Stride<'a, T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Stride<'a, T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Stride<'a, T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'a, T: Ord + 'a> Ord for Stride<'a, T>
[src]
fn cmp(&self, __arg_0: &Stride<'a, T>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<'a, T: Sync> Sync for Stride<'a, T>
[src]
impl<'a, T: Send> Send for Stride<'a, T>
[src]
impl<'a, T: Debug> Debug for Stride<'a, T>
[src]
impl<'a, T> Index<usize> for Stride<'a, T>
[src]
type Output = T
The returned type after indexing
fn index<'b>(&'b self, n: usize) -> &'b T
The method for the indexing (container[index]
) operation
impl<'a, T> IndexMut<usize> for Stride<'a, T>
[src]
fn index_mut<'b>(&'b mut self, n: usize) -> &'b mut T
The method for the mutable indexing (container[index]
) operation
impl<'a, T> Deref for Stride<'a, T>
[src]
type Target = Stride<'a, T>
The resulting type after dereferencing
fn deref<'b>(&'b self) -> &'b Stride<'a, T>
The method called to dereference a value