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
use crate::counter::Counter;
/// Conversion into a [`Counter`].
///
/// # Examples
///
/// This trait is implemented for unsigned integers over
/// [`ItemsCount`](crate::counter::ItemsCount):
///
/// ```
/// #[divan::bench]
/// fn sort_values(bencher: divan::Bencher) {
/// # type T = String;
/// let mut values: Vec<T> = // ...
/// # Vec::new();
/// bencher
/// .counter(values.len())
/// .bench_local(|| {
/// divan::black_box(&mut values).sort();
/// });
/// }
/// ```
pub trait IntoCounter {
/// Which kind of counter are we turning this into?
type Counter: Counter;
/// Converts into a [`Counter`].
fn into_counter(self) -> Self::Counter;
}
impl<C: Counter> IntoCounter for C {
type Counter = C;
#[inline]
fn into_counter(self) -> Self::Counter {
self
}
}