Indices

Struct Indices 

Source
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: usize

Implementations§

Source§

impl Indices

Source

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.

Source

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.

Source

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..

Source

pub fn middle(&self) -> usize

Computes the mid-point between the left and right indices. Uses integer division, so use with care.

Trait Implementations§

Source§

impl Clone for Indices

Source§

fn clone(&self) -> Indices

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Indices

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Indices

Source§

fn eq(&self, other: &Indices) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Indices

Source§

impl Eq for Indices

Source§

impl StructuralPartialEq for Indices

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.