pub enum EnumValue<E: Enumeration> {
Known(E),
Unknown(i32),
}Expand description
A protobuf enum field value that can hold either a known variant or an
unknown i32 value.
Used for open enums (the default in editions). Open enums accept any
i32 value on the wire, even if it doesn’t correspond to a known variant.
§Conversion
Use .into() to populate an open enum field from either a
generated enum variant or a raw integer. Known variants become
Known; unrecognized integers are preserved as
Unknown.
use buffa::EnumValue;
// A variant converts into a known value.
let known: EnumValue<Status> = Status::Active.into();
assert_eq!(known, EnumValue::Known(Status::Active));
// An integer off the wire that no variant matches is preserved as-is.
let unknown: EnumValue<Status> = 99.into();
assert_eq!(unknown, EnumValue::Unknown(99));Variants§
Implementations§
Source§impl<E: Enumeration> EnumValue<E>
impl<E: Enumeration> EnumValue<E>
Sourcepub fn is_known(&self) -> bool
pub fn is_known(&self) -> bool
Returns true if this is a known enum variant.
This is a shorthand for self.as_known().is_some(), mirroring the
MessageField::is_set pattern.
Sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Returns true if the wire value was not recognized as a known variant.
Trait Implementations§
Source§impl<'a, E: Enumeration + Arbitrary<'a>> Arbitrary<'a> for EnumValue<E>
Available on crate feature arbitrary only.
impl<'a, E: Enumeration + Arbitrary<'a>> Arbitrary<'a> for EnumValue<E>
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreimpl<E: Copy + Enumeration> Copy for EnumValue<E>
Source§impl<E: Enumeration> Debug for EnumValue<E>
impl<E: Enumeration> Debug for EnumValue<E>
Source§impl<E: Enumeration> Default for EnumValue<E>
impl<E: Enumeration> Default for EnumValue<E>
Source§fn default() -> Self
fn default() -> Self
Returns the default value for this enum field.
Per the protobuf specification, the default value for an enum field is
the variant whose wire value is 0. If 0 is not a defined variant of
E, this returns EnumValue::Unknown(0), which is
the correct protobuf default but may be surprising — the field’s default
is technically an unknown variant.
Source§impl<'de, E: Enumeration> Deserialize<'de> for EnumValue<E>
Available on crate feature json only.
impl<'de, E: Enumeration> Deserialize<'de> for EnumValue<E>
json only.Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl<E: Enumeration> Display for EnumValue<E>
impl<E: Enumeration> Display for EnumValue<E>
impl<E: Eq + Enumeration> Eq for EnumValue<E>
Source§impl<E: Enumeration> From<E> for EnumValue<E>
impl<E: Enumeration> From<E> for EnumValue<E>
Source§impl<E: Enumeration> PartialEq<E> for EnumValue<E>
Compare an EnumValue directly with a known variant: field == MyEnum::Foo.
impl<E: Enumeration> PartialEq<E> for EnumValue<E>
Compare an EnumValue directly with a known variant: field == MyEnum::Foo.
Returns true only when self is Known(e) and e == *other.
An Unknown value is never equal to any known variant.
§Asymmetry
Only the EnumValue == E direction is available; the reverse E == EnumValue is not implementable due to the orphan rule. If you need to
compare in that order, use field.as_known() == Some(variant) instead.
Source§impl<E: Enumeration> ProtoElemJson for EnumValue<E>where
Self: Serialize + DeserializeOwned,
Available on crate feature json only.
impl<E: Enumeration> ProtoElemJson for EnumValue<E>where
Self: Serialize + DeserializeOwned,
json only.Source§fn serialize_proto_json<S: Serializer>(
v: &Self,
s: S,
) -> Result<S::Ok, S::Error>
fn serialize_proto_json<S: Serializer>( v: &Self, s: S, ) -> Result<S::Ok, S::Error>
Source§fn deserialize_proto_json<'de, D: Deserializer<'de>>(
d: D,
) -> Result<Self, D::Error>
fn deserialize_proto_json<'de, D: Deserializer<'de>>( d: D, ) -> Result<Self, D::Error>
Source§impl<E: Enumeration> Serialize for EnumValue<E>
Available on crate feature json only.
impl<E: Enumeration> Serialize for EnumValue<E>
json only.