Skip to main content

Bound

Enum Bound 

Source
pub enum Bound {
    Inclusive,
    Exclusive,
}
Expand description

Does a search from an anchor consider the anchor itself?

This existed as a choice between two function names (step vs step_inclusive) plus, at one call site, a saturating_sub(1) that tried to convert one into the other by arithmetic. Both mistakes are the same mistake, and both are removed by making the bound a value:

  • naming it forces the caller to state intent instead of remembering which function is which;
  • Bound::first_matching never subtracts, so the “back up one to include the anchor” trick — which cannot back up past 0, and therefore made a match at offset 0 unreachable — has nowhere to live.

Variants§

§

Inclusive

The anchor counts. /foo sitting ON a foo finds that one.

§

Exclusive

The anchor does not count. n advances off the current match.

Implementations§

Source§

impl Bound

Source

pub const fn admits_forward(self, candidate: usize, anchor: usize) -> bool

Does candidate lie at-or-after anchor under this bound?

Source

pub const fn admits_backward(self, candidate: usize, anchor: usize) -> bool

Does candidate lie at-or-before anchor under this bound?

Source

pub fn first_matching( self, starts: &[usize], anchor: usize, forward: bool, ) -> Option<usize>

The index of the first ascending starts entry this bound admits, searching forward from anchor.

Total, and correct at 0 by construction — there is no subtraction to saturate. That is the seal on the measured bug: an inclusive search used to be spelled step(from - 1), and 0 - 1 saturates back to 0, so a match at the very start of the file could never be found.

Trait Implementations§

Source§

impl Clone for Bound

Source§

fn clone(&self) -> Bound

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Bound

Source§

impl Debug for Bound

Source§

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

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

impl Default for Bound

Source§

fn default() -> Bound

Returns the “default value” for a type. Read more
Source§

impl Eq for Bound

Source§

impl PartialEq for Bound

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Bound

Auto Trait Implementations§

§

impl Freeze for Bound

§

impl RefUnwindSafe for Bound

§

impl Send for Bound

§

impl Sync for Bound

§

impl Unpin for Bound

§

impl UnsafeUnpin for Bound

§

impl UnwindSafe for Bound

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.