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>
impl<E> BisectSearch<E>
Sourcepub fn new(n: usize, budget: BisectBudget) -> Self
pub fn new(n: usize, budget: BisectBudget) -> Self
Starts a search over n items with the whole range as the first probe.
Sourcepub fn with_max_transient_retries(self, max: usize) -> Self
pub fn with_max_transient_retries(self, max: usize) -> Self
Overrides DEFAULT_MAX_TRANSIENT_RETRIES for this search.
Sourcepub fn next_range(&mut self) -> Option<Range<usize>>
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.
Sourcepub fn report(
&mut self,
range: Range<usize>,
verdict: ProbeVerdict<E>,
) -> Result<(), TransientLimitExceeded>
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.
Sourcepub fn probes_used(&self) -> usize
pub fn probes_used(&self) -> usize
Probes spent so far, net of refunds.
Sourcepub fn transient_retries(&self) -> usize
pub fn transient_retries(&self) -> usize
Transient re-probes taken so far.
Sourcepub fn last_error(&self) -> Option<&E>
pub fn last_error(&self) -> Option<&E>
The most recent error from a probe spanning more than one item.
Sourcepub fn into_outcomes(self) -> BisectOutcomes<E>
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§
Auto Trait Implementations§
impl<E> Freeze for BisectSearch<E>
impl<E> RefUnwindSafe for BisectSearch<E>
impl<E> Send for BisectSearch<E>
impl<E> Sync for BisectSearch<E>
impl<E> Unpin for BisectSearch<E>
impl<E> UnsafeUnpin for BisectSearch<E>
impl<E> UnwindSafe for BisectSearch<E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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