aboutsummaryrefslogtreecommitdiff
path: root/src/enums.rs
blob: 125559b6e2bb1b5c804b0581accff1bd9294b8d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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>;

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