Enumerations
Enums must be exposed via UDL or proc-macros
Simple enums just work:
enum Animal {
Dog,
Cat,
}
and naturally used in the bindings:
Animal.Dog // kotlin
.dog // swift
Animal.DOG() # python
a.is_DOG()
Enums with fields
Enumerations with associated data are supported.
enum IpAddr {
V4 {q1: u8, q2: u8, q3: u8, q4: u8},
V6 {addr: string},
}
Enums can be very flexible (although UDL doesn't support all of this)
#[derive(uniffi::Enum)]
pub enum MyEnum {
None,
Str(String),
All { s: String, i: i64 }
}
Remote, non-exhaustive enums
There are some special considerations here when using UDL