| 1 |
use crate::counter::Counter; |
| 2 |
|
| 3 |
/// Conversion into a [`Counter`]. |
| 4 |
/// |
| 5 |
/// # Examples |
| 6 |
/// |
| 7 |
/// This trait is implemented for unsigned integers over |
| 8 |
/// [`ItemsCount`](crate::counter::ItemsCount): |
| 9 |
/// |
| 10 |
/// ``` |
| 11 |
/// #[divan::bench] |
| 12 |
/// fn sort_values(bencher: divan::Bencher) { |
| 13 |
/// # type T = String; |
| 14 |
/// let mut values: Vec<T> = // ... |
| 15 |
/// # Vec::new(); |
| 16 |
/// bencher |
| 17 |
/// .counter(values.len()) |
| 18 |
/// .bench_local(|| { |
| 19 |
/// divan::black_box(&mut values).sort(); |
| 20 |
/// }); |
| 21 |
/// } |
| 22 |
/// ``` |
| 23 |
pub trait IntoCounter { |
| 24 |
/// Which kind of counter are we turning this into? |
| 25 |
type Counter: Counter; |
| 26 |
|
| 27 |
/// Converts into a [`Counter`]. |
| 28 |
fn into_counter(self) -> Self::Counter; |
| 29 |
} |
| 30 |
|
| 31 |
impl<C: Counter> IntoCounter for C { |
| 32 |
type Counter = C; |
| 33 |
|
| 34 |
#[inline] |
| 35 |
fn into_counter(self) -> Self::Counter { |
| 36 |
self |
| 37 |
} |
| 38 |
} |