protobuf/
enums.rs

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