1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
//! Core module has common/shared math, traits, and utility modules.
use self::traits::ControlFlow;
pub mod math;
pub mod traits;
/// Basic control flow enum that can be used when visiting query results.
#[derive(Debug, Default)]
pub enum Control<B = ()> {
/// Indicates to the query function to continue visiting results.
#[default]
Continue,
/// Indicates to the query function to stop visiting results and return a value.
Break(B),
}
impl<B> ControlFlow for Control<B> {
#[inline]
fn continuing() -> Self {
Control::Continue
}
#[inline]
fn should_break(&self) -> bool {
matches!(*self, Control::Break(_))
}
}
/// Internal macro used for try return on control flow.
macro_rules! try_cf {
($e:expr) => {
match $e {
x => {
if x.should_break() {
return x;
}
}
}
};
}