protobuf/enums.rs
1use std::fmt;
2
3/// Trait implemented by all protobuf enum types.
4///
5/// Additionally, generated enums also implement [`EnumFull`](crate::EnumFull) trait,
6/// which provides access to reflection.
7pub trait Enum: Eq + Sized + Copy + fmt::Debug + Default + Send + Sync + 'static {
8 /// Enum name as specified in `.proto` file.
9 ///
10 /// There's full reflection when non-lite runtime code generation is used,
11 /// and enums implement [`EnumFull`](crate::EnumFull) trait.
12 /// This operation is for lite runtime.
13 const NAME: &'static str;
14
15 /// Get enum `i32` value.
16 fn value(&self) -> i32;
17
18 /// Try to create an enum from `i32` value.
19 /// Return `None` if value is unknown.
20 fn from_i32(v: i32) -> Option<Self>;
21
22 /// Try to create an enum from `&str` value.
23 /// Return `None` if str is unknown.
24 fn from_str(s: &str) -> Option<Self>;
25
26 /// All enum values for enum type.
27 const VALUES: &'static [Self] = &[];
28}