Macro glean_ffi::define_metric[][src]

macro_rules! define_metric {
    ($metric_type : ident => $metric_map : ident
 {
     $(new -> $new_fn :
       ident($($new_argname : ident : $new_argtyp : ty), * $(,) *),) ?
     $(test_get_num_recorded_errors -> $test_get_num_recorded_errors_fn :
       ident,) ? destroy -> $destroy_fn : ident,
     $($op : ident -> $op_fn :
       ident($($op_argname : ident : $op_argtyp : ty), * $(,) *)), * $(,) *
 }) => { ... };
}
Expand description

Define the global handle map, constructor and destructor functions and any user-defined functions for a new metric

This allows to define most common functionality and simple operations for a metric type. More complex operations should be written as plain functions directly.

Arguments

  • $metric_type - metric type to use from glean_core, e.g. CounterMetric.
  • $metric_map - name to use for the global name, should be all uppercase, e.g. COUNTER_METRICS.
  • $new_fn(...) - (optional) name of the constructor function, followed by all additional (non-common) arguments.
  • $test_get_num_recorded_errors - (optional) name of the test_get_num_recorded_errors function
  • $destroy - name of the destructor function.

Additional simple functions can be define as a mapping $op -> $op_fn:

  • $op - function on the metric type to call.
  • $op_fn - FFI function name for the operation, followed by its arguments. Arguments are converted into the target type using TryFrom::try_from.