Macro open_enum
macro_rules! open_enum {
(
$(#[$meta:meta])*
$vis:vis struct $name:ident($inner:ty) {
$(
$(#[$member_meta:meta])*
$member:ident = $value:expr
),+ $(,)?
}
$(
aliases {
$(
$(#[$alias_meta:meta])*
$alias:ident = $target:ident
),+ $(,)?
}
)?
) => { ... };
}Expand description
Declares an open QMI enum: a transparent newtype with associated constants.
The modem can send values that the IDL of the crate doesn’t know yet. They
stay representable, unlike with a Rust enum. On the wire, the value is
encoded like the inner integer. The constants work in match patterns.
The macro also implements Encode,
Decode, Debug, the conversions from and into
the inner integer, and a name method. Aliases share the value and the
name of another constant.
§Example
ql_qmi::codec::open_enum! {
/// Storage of a message.
pub struct StorageType(i8) {
/// Stored on the SIM.
UIM = 0,
/// Stored on the modem.
NV = 1,
/// Not stored.
NONE = -1,
}
aliases {
/// Stored on the modem.
MODEM = NV,
}
}
assert_eq!(StorageType::NV.name(), Some("NV"));
assert_eq!(StorageType::MODEM.name(), Some("NV"));
assert_eq!(StorageType::from(7).name(), None);
assert_eq!(format!("{:?}", StorageType::NV), "StorageType::NV");
assert_eq!(format!("{:?}", StorageType(7)), "StorageType(7)");