[][src]Macro stats::define_stats_struct

macro_rules! define_stats_struct {
    ($name:ident ($key:expr, $($pr_name:ident: $pr_type:ty),*) ,
        $( $stat_name:ident: $stat_type:tt($( $params:tt )*) , )+) => { ... };
    ($name:ident ($key:expr) ,
        $( $stat_name:ident: $stat_type:tt($( $params:tt )*) ),*) => { ... };
    ($name:ident ($key:expr) ,
        $( $stat_name:ident: $stat_type:tt($( $params:tt )*) , )+) => { ... };
    ($name:ident ($key:expr, $($pr_name:ident: $pr_type:ty),*) ,
        $( $stat_name:ident: $stat_type:tt($( $params:tt )*) ),*) => { ... };
}

Define a group of stats with dynamic names all parameterized by the same set of parameters. The intention is that when setting up a structure for some entity with associated stats, then the type produced by this macro can be included in that structure, and initialized with the appropriate name(s). This is more efficient than using single static "dynamic_" versions of the counters.

use stats::prelude::*;

define_stats_struct! {
   // struct name, key prefix template, key template params
   MyThingStat("things.{}.{}", mything_name: String, mything_idx: usize),
   cache_miss: counter() // default name from the field
}

struct MyThing {
   stats: MyThingStat,
}

impl MyThing {
   fn new(somename: String, someidx: usize) -> Self {
       MyThing {
          stats: MyThingStat::new(somename, someidx),
          //...
       }
   }
}