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.
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: PartialEq + Enumeration> PartialEq for EnumValue<E>
impl<E: PartialEq + Enumeration> PartialEq 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.impl<E: Enumeration> StructuralPartialEq for EnumValue<E>
Auto Trait Implementations§
impl<E> Freeze for EnumValue<E>where
E: Freeze,
impl<E> RefUnwindSafe for EnumValue<E>where
E: RefUnwindSafe,
impl<E> Send for EnumValue<E>where
E: Send,
impl<E> Sync for EnumValue<E>where
E: Sync,
impl<E> Unpin for EnumValue<E>where
E: Unpin,
impl<E> UnsafeUnpin for EnumValue<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for EnumValue<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more