Trait memflow::iter::SplitAtIndex
source · [−]pub trait SplitAtIndex {
fn split_at(self, idx: umem) -> (Option<Self>, Option<Self>)
where
Self: Sized;
unsafe fn split_at_mut(&mut self, idx: umem) -> (Option<Self>, Option<Self>)
where
Self: Sized;
fn length(&self) -> umem;
fn split_inclusive_at(self, idx: umem) -> (Option<Self>, Option<Self>)
where
Self: Sized,
{ ... }
unsafe fn split_inclusive_at_mut(
&mut self,
idx: umem
) -> (Option<Self>, Option<Self>)
where
Self: Sized,
{ ... }
fn split_at_rev(self, idx: umem) -> (Option<Self>, Option<Self>)
where
Self: Sized,
{ ... }
fn size_hint(&self) -> usize { ... }
}
Required methods
Split data at a given index
This method will split the underlying data at a given index into up to 2 possible values.
What a split means very much depends on the underlying type. sizes are split literally, into 2 sizes, one being up to idx, the other being what’s left over. Slices are split into subslices. (Address, impl SplitAtIndex) pairs are split very much like slices (with Address describing the starting address of the data, and the second element being pretty much anything).
But the core idea is - to allow splittable data, be split, in a generic way.
Split data using mutable reference
This should behave the same as split_at, but work with mutable ref being input, instead of the actual value being consumed. This is useful when splitting slices and needing to unsplit them.
Safety
Mutating self reference and returned values after the split is undefined behaviour, because both self, and returned values can point to the same mutable region (for example: &mut u8)
Provided methods
Inclusive version of split_at
This is effectively split_at(idx + 1), with a safeguard for idx == usize::MAX.
Inclusive version of split_at_mut
This is effectively split_at_mut(idx + 1), with a safeguard for idx == usize::MAX.
Safety
The same safety rules apply as with split_at_mut
. Mutating the value after the function
call is undefined, and should not be done until returned values are dropped.
Reverse version of split_at
This will perform splits with index offsetting from the end of the data