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§

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).

Returns the default value for the given protobuf extension field.

See default_value_for_field for more details.

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.

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

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

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

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.

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

See is_valid_for_field for more details.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

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}]");
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.