Skip to main content

StringEnum

Derive Macro StringEnum 

#[derive(StringEnum)]
{
    // Attributes available to this derive:
    #[remora]
}
Expand description

Derives the conversions of an enum that D-Bus sends as a string.

Each unit variant needs #[remora(value = "...")] with its string. One variant with one String field needs #[remora(other)] and keeps any other string.

The derive adds as_str, From<&str>, From<String>, an infallible FromStr, AsRef<str>, Display, zvariant Type, serde Serialize and Deserialize, TryFrom<OwnedValue> and From<Self> for Value.

#[derive(Debug, PartialEq, remora_derive::StringEnum)]
enum State {
    #[remora(value = "on")]
    On,
    #[remora(other)]
    Other(String),
}

assert_eq!(State::from("on"), State::On);
assert_eq!(State::from("off"), State::Other("off".to_owned()));