Macro average::define_histogram

source ·
macro_rules! define_histogram {
    ($name:ident, $LEN:expr) => { ... };
}
Expand description

Define a histogram with a number of bins known at compile time.

Because macros are not hygienic for items, everything is defined in a private module with the given name. This includes the Histogram struct, the number of bins LEN and the histogram iterator HistogramIter.

Note that you need to make sure that core is accessible to the macro.

§Example

use average::{Histogram, define_histogram};

define_histogram!(hist, 10);
let mut h = hist::Histogram::with_const_width(0., 100.);
for i in 0..100 {
    h.add(i as f64).unwrap();
}
assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]);