pub struct Control<'a> { /* private fields */ }Expand description
How a caller stops an operation: a poll, a budget of steps, both or
neither. Every operation on a model, and every long query beside one,
takes one last; Control::NONE is what a caller that does not care
passes.
A step is one iteration of a loop whose trip count is not bounded by the input’s entity count (ADR-0030 §5). Step counts are stable within one release, not across releases: a budget is a cap a caller tunes.
use arris_math::{Control, Meter, Stop};
use core::sync::atomic::{AtomicBool, Ordering};
let stop = AtomicBool::new(false);
let poll = || stop.load(Ordering::Relaxed);
let control = Control::poll(&poll).with_budget(2);
let mut meter = Meter::new(&control);
assert!(meter.tick().is_ok() && meter.tick().is_ok());
let spent = meter.tick().unwrap_err();
assert_eq!((spent.by, spent.steps), (Stop::Budget, 2));
stop.store(true, Ordering::Relaxed);
let stopped = Meter::new(&control).tick().unwrap_err();
assert_eq!((stopped.by, stopped.steps), (Stop::Poll, 0));Implementations§
Trait Implementations§
impl<'a> Copy for Control<'a>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Control<'a>
impl<'a> !UnwindSafe for Control<'a>
impl<'a> Freeze for Control<'a>
impl<'a> Send for Control<'a>
impl<'a> Sync for Control<'a>
impl<'a> Unpin for Control<'a>
impl<'a> UnsafeUnpin for Control<'a>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.