Skip to main content

IntEnum

Derive Macro IntEnum 

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

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

Each unit variant needs #[remora(value = ...)] with its integer. One variant with one integer field needs #[remora(other)] and keeps any other integer. The type of that field sets the D-Bus type.

The derive adds value, From the integer and back, zvariant Type, serde Serialize and Deserialize, TryFrom<OwnedValue> and From<Self> for Value.

#[derive(Debug, PartialEq, remora_derive::IntEnum)]
enum Level {
    #[remora(value = 1)]
    Low,
    #[remora(other)]
    Other(u32),
}

assert_eq!(Level::from(1), Level::Low);
assert_eq!(Level::from(7).value(), 7);