pub trait Enumeration:
Clone
+ Copy
+ PartialEq
+ Eq
+ Hash
+ Debug {
// Required methods
fn from_i32(value: i32) -> Option<Self>;
fn to_i32(&self) -> i32;
fn proto_name(&self) -> &'static str;
// Provided methods
fn from_proto_name(_name: &str) -> Option<Self> { ... }
fn values() -> &'static [Self] { ... }
}Expand description
Trait implemented by all generated protobuf enum types.
Required Methods§
Sourcefn from_i32(value: i32) -> Option<Self>
fn from_i32(value: i32) -> Option<Self>
Convert from an i32 wire value to the enum.
Returns Some for known variants, None for unknown values.
Sourcefn proto_name(&self) -> &'static str
fn proto_name(&self) -> &'static str
The name of this enum variant as it appears in the .proto file.
Provided Methods§
Sourcefn from_proto_name(_name: &str) -> Option<Self>
fn from_proto_name(_name: &str) -> Option<Self>
Look up a variant by its protobuf name string.
Returns Some for recognized names, None for unrecognized names.
The default implementation always returns None; generated code
overrides this with a match on all known variant names.
Sourcefn values() -> &'static [Self]
fn values() -> &'static [Self]
All known variants of this enum, in proto declaration order.
Generated impl Enumeration blocks override this with a static
slice of every variant. The default implementation returns an
empty slice so out-of-tree consumers implementing this trait
against an older codegen version continue to compile — they
should override the default once regenerated.
§Example
for variant in MyEnum::values() {
println!("{:?} = {}", variant, variant.to_i32());
}
assert!(MyEnum::values().contains(&MyEnum::Active));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".