use std::sync::Arc;
use super::Req;
pub trait Scope: Send + Sync + 'static {
fn applies_to(&self, req: &super::Req) -> bool;
}
pub struct ScopeFn<F>(pub(crate) F);
impl<F> Scope for ScopeFn<F>
where
F: Fn(&Req) -> bool + Send + Sync + 'static,
{
fn applies_to(&self, req: &Req) -> bool {
(self.0)(req)
}
}
#[derive(Clone)]
pub(crate) enum Scoped {
Unscoped,
Dyn(Arc<dyn Scope>),
}
impl Scoped {
pub(super) fn applies_to(&self, req: &super::Req) -> bool {
let ret = match self {
Scoped::Unscoped => true,
Scoped::Dyn(s) => s.applies_to(req),
};
trace!("retry in scope: {ret}");
ret
}
}