arch_pkg_text/desc/misc/reuse_advice.rs
1pub use crate::misc::{False, StaticBool, True};
2
3/// Denote whether a certain querier should be reused.
4///
5/// "Reuse" means to call methods of [`Query`](crate::desc::Query) and/or [`QueryMut`](crate::desc::QueryMut) more than once.
6pub trait ReuseAdvice {
7 /// Whether the querier should be reused.
8 type ShouldReuse: StaticBool + ?Sized;
9}
10
11/// Utility to lookup the `bool` value of [`ReuseAdvice`].
12pub trait ReuseAdviceBool: ReuseAdvice {
13 /// The value of [`ReuseAdvice::ShouldReuse`] as a bool.
14 const SHOULD_REUSE: bool = <Self::ShouldReuse>::VALUE;
15}
16impl<Querier: ReuseAdvice + ?Sized> ReuseAdviceBool for Querier {}
17
18/// Utility to lookup the `bool` value of `self` whose type implements [`ReuseAdvice`].
19///
20/// This trait is the dyn-friendly version of [`ReuseAdviceBool`].
21pub trait ReuseAdviceSelf: ReuseAdvice {
22 /// Determine wether `self` [should be reused](ReuseAdvice).
23 fn should_reuse(&self) -> bool {
24 Self::SHOULD_REUSE
25 }
26}
27impl<Querier: ReuseAdvice + ?Sized> ReuseAdviceSelf for Querier {}
28
29/// Querier types that implement this trait should be reused.
30///
31/// This trait is a convenient alias for [`ReuseAdvice`] with value [`True`].
32pub trait ShouldReuse: ReuseAdvice<ShouldReuse = True> {}
33impl<Querier: ReuseAdvice<ShouldReuse = True> + ?Sized> ShouldReuse for Querier {}