diff options
author | Andrei Homescu <ahomescu@google.com> | 2021-06-29 23:55:43 +0000 |
---|---|---|
committer | Andrei Homescu <ahomescu@google.com> | 2021-07-01 05:38:46 +0000 |
commit | 7f38cf97916ec0b12b4aced663462e56dd8fe0b3 (patch) | |
tree | 19035feaf69360ef101214d0d6bdc14c8911d227 | |
parent | 07ac6eefffa4822a2e40c2e497bd4a5dae402958 (diff) | |
download | native-7f38cf97916ec0b12b4aced663462e56dd8fe0b3.tar.gz |
libbinder_rs: Add enum_values function to AIDL enums
This auto-generates an enum_values function for all
Rust AIDL enums that works very similarly to enum_range()
in C++.
Bug: 179438017
Test: m
Change-Id: Ice74682dc9e1119aca2a932c3d5644665963dad8
-rw-r--r-- | libs/binder/rust/src/binder.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libs/binder/rust/src/binder.rs b/libs/binder/rust/src/binder.rs index f79b1b7023..dd0c7b82e0 100644 --- a/libs/binder/rust/src/binder.rs +++ b/libs/binder/rust/src/binder.rs @@ -897,7 +897,7 @@ macro_rules! declare_binder_interface { #[macro_export] macro_rules! declare_binder_enum { { - $enum:ident : $backing:ty { + $enum:ident : [$backing:ty; $size:expr] { $( $name:ident = $value:expr, )* } } => { @@ -905,6 +905,11 @@ macro_rules! declare_binder_enum { pub struct $enum(pub $backing); impl $enum { $( pub const $name: Self = Self($value); )* + + #[inline(always)] + pub const fn enum_values() -> [Self; $size] { + [$(Self::$name),*] + } } impl $crate::parcel::Serialize for $enum { |