Skip to main content

Levels

Derive Macro Levels 

Source
#[derive(Levels)]
{
    // Attributes available to this derive:
    #[system2]
}
Expand description

Derives Levels for an enum, so that its variants are the levels of a Score.

The variants are the levels, from the lowest to the highest. Each variant must be a unit variant. The API knows a level only by its text. Thus a level sends its description: the doc comment of the variant, or the value of #[system2(description = "…")]. The doc comment is the text that rustdoc shows. If no variant has a description, each level is the name of its variant in snake case, with no r#. If only some variants have one, each other variant is a compile error. The enum has 1 to 10 variants, and each level is different.

§Examples

use system2::{Levels, Score, score};

#[derive(Debug, Clone, Copy, PartialEq, Levels)]
enum Severity {
    /// Nothing breaks.
    Minor,
    /// A feature breaks for some customers.
    Major,
    /// The level that pages the engineer on call.
    #[system2(description = "Data is lost.")]
    Critical,
}

const SEVERITY: Score<Severity> = score!("How severe is the bug?", Severity);