pub struct Indices {
pub left: usize,
pub right: usize,
}Expand description
The left and right indices, which in combination with the slice held by the Bisector, provide
the view on which a bisection step can be applied.
The Bisector::bisect and Bisector::try_bisect methods take these Indices as input, and
produce a new Indices copy as output (the indices of the one step further converged area are
produced as output).
Fields§
§left: usize§right: usizeImplementations§
Source§impl Indices
impl Indices
Sourcepub fn new(left_index: usize, right_index: usize) -> Self
pub fn new(left_index: usize, right_index: usize) -> Self
Create a new pair of indices.
When used with Bisector
The left index must be smaller or equal to the right index left <= right,
for the Bisector to work properly.
It’s up to the implementor to uphold this requirement.
Sourcepub fn from_bisector<T>(bisector: &Bisector<'_, T>) -> Self
pub fn from_bisector<T>(bisector: &Bisector<'_, T>) -> Self
Re-use the slice of the Bisector to determine the starting indices.
The returned indices will be the complete range of the slice, i.e. from index 0 to
index |slice| - 1 (length of slice minus 1, i.e. the last index of the slice).
NB: The slice given to Bisector must not be empty.
Consider using the fallible function Indices::try_from_bisector when possible.
§Undefined behaviour
If the slice given to Bisector is empty, the resulting behaviour may not be as expected.
In addition, semantically different behaviour may occur when compiling with rustc
debug or release mode.
Debug mode
In rustc debug mode, if the slice is empty, i.e. the length of the slice is 0, this function
will panic, by virtue of debug mode out of bounds checking.
Release mode
In rustc release mode, if the slice is empty, i.e. the length of the slice is 0, the value
set to the right index will underflow, resulting in undefined behaviour.
Sourcepub fn try_from_bisector<T>(
bisector: &Bisector<'_, T>,
) -> Result<Self, EmptySliceError>
pub fn try_from_bisector<T>( bisector: &Bisector<'_, T>, ) -> Result<Self, EmptySliceError>
Re-use the slice of the Bisector to determine the starting indices.
The returned indices will be the complete range of the slice, i.e. from index 0 to
index |slice| - 1 (length of slice minus 1, i.e. the last index of the slice).
The slice given to Bisector must not be empty. If it is, an EmptySliceError
Err result will be returned..