Enum prost_reflect::Value
source · pub enum 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
impl Value
sourcepub fn default_value_for_field(field_desc: &FieldDescriptor) -> Self
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).
sourcepub fn default_value_for_extension(extension_desc: &ExtensionDescriptor) -> Self
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.
sourcepub fn default_value(kind: &Kind) -> Self
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.
sourcepub fn is_default_for_field(&self, field_desc: &FieldDescriptor) -> bool
pub fn is_default_for_field(&self, field_desc: &FieldDescriptor) -> bool
Returns true
if this is the default value for the given protobuf field.
sourcepub fn is_default_for_extension(
&self,
extension_desc: &ExtensionDescriptor,
) -> bool
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.
sourcepub fn is_default(&self, kind: &Kind) -> bool
pub fn is_default(&self, kind: &Kind) -> bool
Returns true
if this is the default value for the given protobuf type kind
.
sourcepub fn is_valid_for_field(&self, field_desc: &FieldDescriptor) -> bool
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.
sourcepub fn is_valid_for_extension(
&self,
extension_desc: &ExtensionDescriptor,
) -> bool
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.
sourcepub fn is_valid(&self, kind: &Kind) -> bool
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.
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the value if it is a Value::Bool
, or None
if it is any other type.
sourcepub fn as_bool_mut(&mut self) -> Option<&mut bool>
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.
sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Returns the value if it is a Value::U32
, or None
if it is any other type.
sourcepub fn as_u32_mut(&mut self) -> Option<&mut u32>
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.
sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Returns the value if it is a Value::U64
, or None
if it is any other type.
sourcepub fn as_u64_mut(&mut self) -> Option<&mut u64>
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.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the value if it is a Value::I64
, or None
if it is any other type.
sourcepub fn as_i64_mut(&mut self) -> Option<&mut i64>
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.
sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
Returns the value if it is a Value::I32
, or None
if it is any other type.
sourcepub fn as_i32_mut(&mut self) -> Option<&mut i32>
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.
sourcepub fn as_f32(&self) -> Option<f32>
pub fn as_f32(&self) -> Option<f32>
Returns the value if it is a Value::F32
, or None
if it is any other type.
sourcepub fn as_f32_mut(&mut self) -> Option<&mut f32>
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.
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the value if it is a Value::F64
, or None
if it is any other type.
sourcepub fn as_f64_mut(&mut self) -> Option<&mut f64>
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.
sourcepub fn as_enum_number(&self) -> Option<i32>
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.
sourcepub fn as_enum_number_mut(&mut self) -> Option<&mut i32>
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.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the value if it is a Value::String
, or None
if it is any other type.
sourcepub fn as_string_mut(&mut self) -> Option<&mut String>
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.
sourcepub fn as_bytes(&self) -> Option<&Bytes>
pub fn as_bytes(&self) -> Option<&Bytes>
Returns the value if it is a Value::Bytes
, or None
if it is any other type.
sourcepub fn as_bytes_mut(&mut self) -> Option<&mut Bytes>
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.
sourcepub fn as_message(&self) -> Option<&DynamicMessage>
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.
sourcepub fn as_message_mut(&mut self) -> Option<&mut DynamicMessage>
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.
sourcepub fn as_list(&self) -> Option<&[Value]>
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.
sourcepub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>>
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.
sourcepub fn as_map(&self) -> Option<&HashMap<MapKey, Value>>
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.
sourcepub fn as_map_mut(&mut self) -> Option<&mut HashMap<MapKey, Value>>
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.
sourcepub fn into_map_key(self) -> Option<MapKey>
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 Display for Value
impl Display for Value
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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}]");
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> 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,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)