1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::fmt;

/// Trait implemented by all protobuf enum types.
///
/// Additionally, generated enums also implement [`EnumFull`](crate::EnumFull) trait,
/// which provides access to reflection.
pub trait Enum: Eq + Sized + Copy + fmt::Debug + Default + Send + Sync + 'static {
    /// Enum name as specified in `.proto` file.
    ///
    /// There's full reflection when non-lite runtime code generation is used,
    /// and enums implement [`EnumFull`](crate::EnumFull) trait.
    /// This operation is for lite runtime.
    const NAME: &'static str;

    /// Get enum `i32` value.
    fn value(&self) -> i32;

    /// Try to create an enum from `i32` value.
    /// Return `None` if value is unknown.
    fn from_i32(v: i32) -> Option<Self>;

    /// Try to create an enum from `&str` value.
    /// Return `None` if str is unknown.
    fn from_str(s: &str) -> Option<Self>;

    /// All enum values for enum type.
    const VALUES: &'static [Self] = &[];
}