pub trait OptionalDescription {
// Required method
fn description(&self) -> Option<&'static str>;
}Expand description
Like [Display], but ['static], no_std and no_alloc.
See also Description
§Example
#[derive(OptionalDescription)]
enum BatteryStatus {
Okay,
#[description("Low battery!")]
LowBattery,
#[description("Fully charged! Please remove the charger.")]
FullyCharged,
}
fn main() {
let battery1 = BatteryStatus::LowBattery;
let battery2 = BatteryStatus::Okay;
if let Some(description) = battery1.description() {
println!("Battery notification: {}", description);
}
if let Some(description) = battery2.description() {
println!("Battery notification: {}", description);
}
// Battery notification: Low battery!
//
}