1 use reflect::EnumDescriptor;
2 use reflect::EnumValueDescriptor;
3 
4 /// Trait implemented by all protobuf enum types.
5 pub trait ProtobufEnum: Eq + Sized + Copy + 'static {
6     /// Get enum `i32` value.
value(&self) -> i327     fn value(&self) -> i32;
8 
9     /// Try to create an enum from `i32` value.
10     /// Return `None` if value is unknown.
from_i32(v: i32) -> Option<Self>11     fn from_i32(v: i32) -> Option<Self>;
12 
13     /// Get all enum values for enum type.
values() -> &'static [Self]14     fn values() -> &'static [Self] {
15         panic!();
16     }
17 
18     /// Get enum value descriptor.
descriptor(&self) -> &'static EnumValueDescriptor19     fn descriptor(&self) -> &'static EnumValueDescriptor {
20         self.enum_descriptor().value_by_number(self.value())
21     }
22 
23     /// Get enum descriptor.
enum_descriptor(&self) -> &'static EnumDescriptor24     fn enum_descriptor(&self) -> &'static EnumDescriptor {
25         Self::enum_descriptor_static()
26     }
27 
28     /// Get enum descriptor by type.
enum_descriptor_static() -> &'static EnumDescriptor29     fn enum_descriptor_static() -> &'static EnumDescriptor {
30         panic!();
31     }
32 }
33