[−][src]Attribute Macro metered_macro::error_count
#[error_count]
A procedural macro that generates a new metric that measures the amount
of times each variant of an error has been thrown, to be used as crate-specific
replacement for metered::ErrorCount
.
#[error_count(name = LibErrorCount, visibility = pub)] #[derive(Debug, Error)] pub enum LibError { ReadError, InitError, } #[error_count(name = ErrorCount, visibility = pub)] #[derive(Debug, Error)] pub enum Error { MyLibrary(#[from] #[nested] LibError), } #[derive(Default, Debug)] pub struct Baz { metrics: BazMetrics, } #[metered(registry = BazMetrics)] impl Baz { #[measure(ErrorCount)] pub fn biz(&self) -> Result<(), Error> { Err(LibError::InitError.into()) } } let baz = Baz::default(); baz.biz(); assert_eq!(baz.metrics.biz.error_count.my_library.read_error.get(), 0); assert_eq!(baz.metrics.biz.error_count.my_library.init_error.get(), 1);
name
is required and must be a valid Rust ident, this is the name of the generated struct containing a counter for each enum variant.visibility
specifies to visibility of the generated struct, it defaults topub(crate)
.
The error_count
macro may only be applied to any enums that have a
std::error::Error
impl. The generated struct may then be included
in measure
attributes to measure the amount of errors returned of
each variant defined in your error enum.