Expand description
Provides trait and functions to log mapping from IDs of an enum to its variants or mapped variant values.
§Example
use diagnostics_assertions::assert_data_tree;
use fuchsia_inspect::Inspector;
use strum_macros::{Display, EnumIter};
#[derive(Display, EnumIter)]
enum Enum {
A,
B,
}
impl IdEnum for Enum {
type Id = u8;
fn to_id(&self) -> Self::Id {
match self {
Self::A => 0,
Self::B => 1,
}
}
}
let inspector = Inspector::default();
inspect_record_id_enum::<Enum>(inspector.root(), "enum");
assert_data_tree!(inspector, root: {
"enum": {
"0": "A",
"1": "B",
}
});
inspect_record_id_enum_mapped::<Enum, _>(inspector.root(), "highlight", |variant| {
match variant {
Enum::A => None,
Enum::B => Some(2u8),
}
});
assert_data_tree!(inspector, root: contains {
"highlight": {
"1": 2u64,
}
});
Traits§
Functions§
- Record the mapping of
IdEnum
’s ids to variants in Inspect. - Record the mapping of
IdEnum
’s ids to mapped variant values. Only variants with mappedSome
values are recorded.