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

Field descriptor.

Can be used for runtime reflection.

Implementations§

source§

impl FieldDescriptor

source

pub fn proto(&self) -> &'static FieldDescriptorProto

Get .proto description of field

source

pub fn name(&self) -> &'static str

Field name as specified in .proto file

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_repeated(&self) -> bool

If this field repeated?

source

pub fn has_field(&self, m: &dyn Message) -> 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 len_field(&self, m: &dyn Message) -> usize

Return length of repeated field.

For singular field return 1 if field is set and 0 otherwise.

Panics

If this field belongs to a different message type.

source

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

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 get_enum(&self, m: &dyn Message) -> &'static EnumValueDescriptor

Get enum field.

Panics

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

source

pub fn get_str<'a>(&self, m: &'a dyn Message) -> &'a str

Get string field.

Panics

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

source

pub fn get_bytes<'a>(&self, m: &'a dyn Message) -> &'a [u8]

Get bytes field.

Panics

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

source

pub fn get_u32(&self, m: &dyn Message) -> u32

Get u32 field.

Panics

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

source

pub fn get_u64(&self, m: &dyn Message) -> u64

Get u64 field.

Panics

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

source

pub fn get_i32(&self, m: &dyn Message) -> i32

Get i32 field.

Panics

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

source

pub fn get_i64(&self, m: &dyn Message) -> i64

Get i64 field.

Panics

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

source

pub fn get_bool(&self, m: &dyn Message) -> bool

Get bool field.

Panics

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

source

pub fn get_f32(&self, m: &dyn Message) -> f32

Get float field.

Panics

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

source

pub fn get_f64(&self, m: &dyn Message) -> f64

Get double field.

Panics

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

source

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

Get field of any type.

Panics

If this field belongs to a different message type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.