Skip to main content

BisectSearch

Struct BisectSearch 

Source
pub struct BisectSearch<E> { /* private fields */ }
Expand description

Drives a bisect over n items: which range to probe next, and what each verdict means for the ranges still outstanding.

let mut search = BisectSearch::new(items.len(), BisectBudget::Auto);
while let Some(range) = search.next_range() {
    // The caller owns the operation — one shared transaction, or a fresh
    // one committed per range.
    let verdict = probe(&items[range.clone()]).await;
    search.report(range, verdict)?;
}
let outcomes = search.into_outcomes();

Implementations§

Source§

impl<E> BisectSearch<E>

Source

pub fn new(n: usize, budget: BisectBudget) -> Self

Starts a search over n items with the whole range as the first probe.

Source

pub fn with_max_transient_retries(self, max: usize) -> Self

Overrides DEFAULT_MAX_TRANSIENT_RETRIES for this search.

Source

pub fn next_range(&mut self) -> Option<Range<usize>>

The next range to probe: the largest outstanding one, earliest start breaking ties.

None when everything is resolved or the budget is spent — items still inside unprobed ranges resolve as ItemOutcome::Unresolved.

Source

pub fn report( &mut self, range: Range<usize>, verdict: ProbeVerdict<E>, ) -> Result<(), TransientLimitExceeded>

Records what a probe found.

Errors once the transient allowance is exhausted, at which point the search is over — see TransientLimitExceeded.

Source

pub fn probes_used(&self) -> usize

Probes spent so far, net of refunds.

Source

pub fn transient_retries(&self) -> usize

Transient re-probes taken so far.

Source

pub fn last_error(&self) -> Option<&E>

The most recent error from a probe spanning more than one item.

Source

pub fn into_outcomes(self) -> BisectOutcomes<E>

Finishes the search, resolving anything still outstanding as ItemOutcome::Unresolved so every input gets exactly one outcome.

Trait Implementations§

Source§

impl<E: Debug> Debug for BisectSearch<E>

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more