pub struct FieldDescriptor { /* private fields */ }
Expand description

Field descriptor.

Can be used for runtime reflection.

Implementations§

source§

impl FieldDescriptor

source

pub fn proto(&self) -> &FieldDescriptorProto

Get .proto description of field

source

pub fn name(&self) -> &str

Field name as specified in .proto file.

source

pub fn number(&self) -> i32

Field number as specified in .proto file.

source

pub fn full_name(&self) -> String

Fully qualified name of the field: fully qualified name of the declaring type followed by the field name.

Declaring type is a message (for regular field or extensions) or a package (for top-level extensions).

source

pub fn containing_oneof_including_synthetic(&self) -> Option<OneofDescriptor>

Oneof descriptor containing this field. Do not skip synthetic oneofs.

source

pub fn containing_oneof(&self) -> Option<OneofDescriptor>

Oneof containing this field.

Return None if this field is not part of oneof or if it is synthetic oneof.

source

pub fn containing_message(&self) -> MessageDescriptor

Message which contains this field.

For extension fields, this is the message being extended.

source

pub fn json_name(&self) -> &str

JSON field name.

Can be different from .proto field name.

See JSON mapping for details.

source

pub fn is_singular(&self) -> bool

If this field is optional or required.

source

pub fn is_required(&self) -> bool

Is this field required.

source

pub fn is_repeated_or_map(&self) -> bool

If this field repeated or map?

source

pub fn is_repeated(&self) -> bool

Is this field repeated, but not map field?

source

pub fn is_map(&self) -> bool

If this field a map field?

source

pub fn has_field(&self, m: &dyn MessageDyn) -> bool

Check if field is set in given message.

For repeated field or map field return true if collection is not empty.

§Panics

If this field belongs to a different message type.

source

pub fn get_message<'a>(&self, m: &'a dyn MessageDyn) -> MessageRef<'a>

Get message field or default instance if field is unset.

§Panics

If this field belongs to a different message type or field type is not message.

source

pub fn mut_message<'a>( &self, m: &'a mut dyn MessageDyn ) -> &'a mut dyn MessageDyn

Get a mutable reference to a message field. Initialize field with default message if unset.

§Panics

If this field belongs to a different message type or field type is not singular message.

source

pub fn singular_default_value(&self) -> ReflectValueRef<'_>

Default value.

§Panics

If field is not singular.

source

pub fn get_singular_field_or_default<'a>( &self, m: &'a dyn MessageDyn ) -> ReflectValueRef<'a>

Get singular field value.

Return field default value if field is unset.

§Panics

If this field belongs to a different message type or fields is not singular.

source

pub fn singular_runtime_type(&self) -> RuntimeType

Runtime representation of singular field.

§Panics

If this field belongs to a different message type or field is not singular.

source

pub fn set_singular_field(&self, m: &mut dyn MessageDyn, value: ReflectValueBox)

Set singular field.

§Panics

If this field belongs to a different message type or field is not singular or value is of different type.

source

pub fn clear_field(&self, m: &mut dyn MessageDyn)

Clear a field.

source

pub fn runtime_field_type(&self) -> RuntimeFieldType

Dynamic representation of field type.

source

pub fn get_reflect<'a>(&self, m: &'a dyn MessageDyn) -> ReflectFieldRef<'a>

Get field of any type.

§Panics

If this field belongs to a different message type.

source

pub fn get_singular<'a>( &self, m: &'a dyn MessageDyn ) -> Option<ReflectValueRef<'a>>

Get singular field value.

Return None if field is unset.

§Panics

If this field belongs to a different message type or fields is not singular.

source

pub fn get_repeated<'a>(&self, m: &'a dyn MessageDyn) -> ReflectRepeatedRef<'a>

Get repeated field.

§Panics

If this field belongs to a different message type or field is not repeated.

source

pub fn mut_repeated<'a>( &self, m: &'a mut dyn MessageDyn ) -> ReflectRepeatedMut<'a>

Get a mutable reference to repeated field.

§Panics

If this field belongs to a different message type or field is not repeated.

source

pub fn get_map<'a>(&self, m: &'a dyn MessageDyn) -> ReflectMapRef<'a>

Get map field.

§Panics

If this field belongs to a different message type or field is not map.

source

pub fn mut_map<'a>(&self, m: &'a mut dyn MessageDyn) -> ReflectMapMut<'a>

Get a mutable reference to map field.

§Panics

If this field belongs to a different message type or field is not map.

Trait Implementations§

source§

impl Clone for FieldDescriptor

source§

fn clone(&self) -> FieldDescriptor

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 Display for FieldDescriptor

source§

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

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

impl PartialEq for FieldDescriptor

source§

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

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

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

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

impl Eq for FieldDescriptor

source§

impl StructuralPartialEq for FieldDescriptor

Auto Trait Implementations§

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