Skip to main content

Value

Enum 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>),
}
Available on crate feature dynamic only.
Expand description

A protobuf field value carried by super::DynamicMessage.

One variant per scalar wire type, plus EnumNumber (open-enum semantics — any i32 is acceptable so unknown variants round-trip losslessly), Message, List, and Map. The variant set mirrors prost-reflect’s Value for consumer migration.

Variants§

§

Bool(bool)

bool.

§

I32(i32)

int32 / sint32 / sfixed32.

§

I64(i64)

int64 / sint64 / sfixed64.

§

U32(u32)

uint32 / fixed32.

§

U64(u64)

uint64 / fixed64.

§

F32(f32)

float.

§

F64(f64)

double.

§

String(String)

string (UTF-8).

§

Bytes(Bytes)

bytes.

§

EnumNumber(i32)

Enum variant by number.

i32 rather than a typed variant so forward-compat decoding (an unknown enum number) round-trips byte-identically. Matches proto3’s open-enum semantics.

§

Message(DynamicMessage)

Sub-message.

§

List(Vec<Value>)

Repeated value (every element validated against the list’s declared element Kind).

§

Map(HashMap<MapKey, Value>)

map<K, V> field.

Implementations§

Source§

impl Value

Source

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

The proto default for the given Kind (singular form).

For Message returns an empty super::DynamicMessage of the declared sub-message type. For Enum, the zero variant.

Source

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

The proto default for field accounting for cardinality (lists and maps default to the empty collection).

Reads any pre-parsed [default = …] from the descriptor pool. When the descriptor declares no explicit default this returns the zero value for the field’s Kind.

Source

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

True iff self equals the proto default for kind.

Lists and maps are default iff empty. Message is default iff it is a fresh, populated-fields-empty instance.

Source

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

Validate that self matches field’s declared shape.

Recursive: list elements validate against the element kind, map keys/values against their declared kinds, and sub-message values must share the field’s expected message descriptor (compared pool-pointer + index).

Source

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

Returns the bool payload, if any.

Source

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

Returns the i32 payload, if any.

Source

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

Returns the i64 payload, if any.

Source

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

Returns the u32 payload, if any.

Source

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

Returns the u64 payload, if any.

Source

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

Returns the f32 payload, if any.

Source

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

Returns the f64 payload, if any.

Source

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

Returns the &str payload, if any.

Source

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

Returns the &Bytes payload, if any.

Source

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

Returns the enum-number payload, if any.

Source

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

Returns the super::DynamicMessage payload, if any.

Source

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

Mutable form of Self::as_message.

Source

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

Returns the list payload, if any.

Source

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

Mutable form of Self::as_list.

Source

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

Returns the map payload, if any.

Source

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

Mutable form of Self::as_map.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 From<&str> for Value

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Source§

fn from(v: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<DynamicMessage> for Value

Source§

fn from(v: DynamicMessage) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Convenience constructors for common literal types.

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 UnsafeUnpin 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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.