Enum prost_reflect::Value

source ·
pub enum Value {
Show 13 variants Bool(bool), I32(i32), I64(i64), U32(u32), U64(u64), F32(f32), F64(f64), String(String), Bytes(Bytes), EnumNumber(i32), Message(DynamicMessage), List(Vec<Value>), Map(HashMap<MapKey, Value>),
}
Expand description

A dynamically-typed protobuf value.

Note this type may map to multiple possible protobuf wire formats, so it must be serialized as part of a DynamicMessage.

Variants§

§

Bool(bool)

A boolean value, encoded as the bool protobuf type.

§

I32(i32)

A 32-bit signed integer, encoded as one of the int32, sint32 or sfixed32 protobuf types.

§

I64(i64)

A 64-bit signed integer, encoded as one of the int64, sint64 or sfixed64 protobuf types.

§

U32(u32)

A 32-bit unsigned integer, encoded as one of the uint32 or ufixed32 protobuf types.

§

U64(u64)

A 64-bit unsigned integer, encoded as one of the uint64 or ufixed64 protobuf types.

§

F32(f32)

A 32-bit floating point number, encoded as the float protobuf type.

§

F64(f64)

A 64-bit floating point number, encoded as the double protobuf type.

§

String(String)

A string, encoded as the string protobuf type.

§

Bytes(Bytes)

A byte string, encoded as the bytes protobuf type.

§

EnumNumber(i32)

An enumeration value, encoded as a protobuf enum.

§

Message(DynamicMessage)

A protobuf message.

§

List(Vec<Value>)

A list of values, encoded as a protobuf repeated field.

§

Map(HashMap<MapKey, Value>)

A map of values, encoded as a protobuf map field.

Implementations§

source§

impl Value

source

pub fn default_value_for_field(field_desc: &FieldDescriptor) -> Self

Returns the default value for the given protobuf field.

This is equivalent to default_value except for the following cases:

  • If the field is a map, an empty map is returned.
  • If the field is repeated, an empty list is returned.
  • If the field has a custom default value specified, that is returned (proto2 only).
source

pub fn default_value_for_extension(extension_desc: &ExtensionDescriptor) -> Self

Returns the default value for the given protobuf extension field.

See default_value_for_field for more details.

source

pub fn default_value(kind: &Kind) -> Self

Returns the default value for the given protobuf type kind.

Unlike default_value_for_field, this method does not look at field cardinality, so it will never return a list or map.

source

pub fn is_default_for_field(&self, field_desc: &FieldDescriptor) -> bool

Returns true if this is the default value for the given protobuf field.

source

pub fn is_default_for_extension( &self, extension_desc: &ExtensionDescriptor, ) -> bool

Returns true if this is the default value for the given protobuf extension field.

source

pub fn is_default(&self, kind: &Kind) -> bool

Returns true if this is the default value for the given protobuf type kind.

source

pub fn is_valid_for_field(&self, field_desc: &FieldDescriptor) -> bool

Returns true if this value can be set for a given field.

Note this only checks if the value can be successfully encoded. It doesn’t check, for example, that enum values are in the defined range.

source

pub fn is_valid_for_extension( &self, extension_desc: &ExtensionDescriptor, ) -> bool

Returns true if this value can be set for a given extension field.

See is_valid_for_field for more details.

source

pub fn is_valid(&self, kind: &Kind) -> bool

Returns true if this value can be encoded as the given Kind.

Unlike is_valid_for_field, this method does not look at field cardinality, so it will never return true for lists or maps.

source

pub fn as_bool(&self) -> Option<bool>

Returns the value if it is a Value::Bool, or None if it is any other type.

source

pub fn as_bool_mut(&mut self) -> Option<&mut bool>

Returns a mutable reference to the value if it is a Value::Bool, or None if it is any other type.

source

pub fn as_u32(&self) -> Option<u32>

Returns the value if it is a Value::U32, or None if it is any other type.

source

pub fn as_u32_mut(&mut self) -> Option<&mut u32>

Returns a mutable reference to the value if it is a Value::U32, or None if it is any other type.

source

pub fn as_u64(&self) -> Option<u64>

Returns the value if it is a Value::U64, or None if it is any other type.

source

pub fn as_u64_mut(&mut self) -> Option<&mut u64>

Returns a mutable reference to the value if it is a Value::U64, or None if it is any other type.

source

pub fn as_i64(&self) -> Option<i64>

Returns the value if it is a Value::I64, or None if it is any other type.

source

pub fn as_i64_mut(&mut self) -> Option<&mut i64>

Returns a mutable reference to the value if it is a Value::I64, or None if it is any other type.

source

pub fn as_i32(&self) -> Option<i32>

Returns the value if it is a Value::I32, or None if it is any other type.

source

pub fn as_i32_mut(&mut self) -> Option<&mut i32>

Returns a mutable reference to the value if it is a Value::I32, or None if it is any other type.

source

pub fn as_f32(&self) -> Option<f32>

Returns the value if it is a Value::F32, or None if it is any other type.

source

pub fn as_f32_mut(&mut self) -> Option<&mut f32>

Returns a mutable reference to the value if it is a Value::F32, or None if it is any other type.

source

pub fn as_f64(&self) -> Option<f64>

Returns the value if it is a Value::F64, or None if it is any other type.

source

pub fn as_f64_mut(&mut self) -> Option<&mut f64>

Returns a mutable reference to the value if it is a Value::F64, or None if it is any other type.

source

pub fn as_enum_number(&self) -> Option<i32>

Returns the value if it is a Value::EnumNumber, or None if it is any other type.

source

pub fn as_enum_number_mut(&mut self) -> Option<&mut i32>

Returns a mutable reference to the value if it is a Value::EnumNumber, or None if it is any other type.

source

pub fn as_str(&self) -> Option<&str>

Returns the value if it is a Value::String, or None if it is any other type.

source

pub fn as_string_mut(&mut self) -> Option<&mut String>

Returns a mutable reference to the value if it is a Value::String, or None if it is any other type.

source

pub fn as_bytes(&self) -> Option<&Bytes>

Returns the value if it is a Value::Bytes, or None if it is any other type.

source

pub fn as_bytes_mut(&mut self) -> Option<&mut Bytes>

Returns a mutable reference to the value if it is a Value::Bytes, or None if it is any other type.

source

pub fn as_message(&self) -> Option<&DynamicMessage>

Returns a a reference to the value if it is a Value::Message, or None if it is any other type.

source

pub fn as_message_mut(&mut self) -> Option<&mut DynamicMessage>

Returns a mutable reference to the value if it is a Value::Message, or None if it is any other type.

source

pub fn as_list(&self) -> Option<&[Value]>

Returns a a reference to the value if it is a Value::List, or None if it is any other type.

source

pub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>>

Returns a mutable reference to the value if it is a Value::List, or None if it is any other type.

source

pub fn as_map(&self) -> Option<&HashMap<MapKey, Value>>

Returns a a reference to the value if it is a Value::Map, or None if it is any other type.

source

pub fn as_map_mut(&mut self) -> Option<&mut HashMap<MapKey, Value>>

Returns a mutable reference to the value if it is a Value::Map, or None if it is any other type.

source

pub fn into_map_key(self) -> Option<MapKey>

Converts this value into a MapKey, or None if it is not a valid map key type.

§Examples
assert_eq!(Value::I32(5).into_map_key(), Some(MapKey::I32(5)));
assert_eq!(Value::String("foo".to_owned()).into_map_key(), Some(MapKey::String("foo".to_owned())));
assert_eq!(Value::Bytes(Bytes::from_static(b"bytes")).into_map_key(), None);

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats this value using the protobuf text format.

§Examples
assert_eq!(format!("{}", Value::String("hello".to_owned())), "\"hello\"");
assert_eq!(format!("{}", Value::List(vec![Value::I32(1), Value::I32(2)])), "[1,2]");
assert_eq!(format!("{}", Value::Map(HashMap::from_iter([(MapKey::I32(1), Value::U32(2))]))), "[{key:1,value:2}]");
// The alternate format specifier may be used to indent the output
assert_eq!(format!("{:#}", Value::Map(HashMap::from_iter([(MapKey::I32(1), Value::U32(2))]))), "[{\n  key: 1\n  value: 2\n}]");
source§

impl From<MapKey> for Value

source§

fn from(value: MapKey) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Value

source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl !Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.