Trait FieldDecode

pub trait FieldDecode<'a, T, R>: Sized {
    const ENTRY: DecoderEntry<'a, T, R> = _;

    // Required methods
    fn read_field(
        item: &mut InplaceOption<'_, T>,
        reader: FieldReader<'a, '_, R>,
    ) -> Result<(), Error>;
    fn default_field(item: &mut InplaceOption<'_, T>) -> Result<(), Error>;

    // Provided methods
    fn packed<'p, C>() -> Option<&'p dyn PackedDecode<'a, T, C>>
       where C: CopyExtend<T>,
             T: 'p { ... }
    fn wrap_in_sequence() -> bool { ... }
    fn read_field_in_sequence(
        item: &mut InplaceOption<'_, T>,
        reader: FieldReader<'a, '_, R>,
    ) -> Result<(), Error> { ... }
}
Expand description

The FieldEncode trait provides a field decoder for type T.

R is the external resource type, which allows decoding objects with non-protobuf resources such as file descriptors. Most implementors of this trait will be generic over all R.

Provided Associated Constants§

const ENTRY: DecoderEntry<'a, T, R> = _

The table decoder entry for this type, used in types from table::decode.

This should not be overridden by implementations.

Required Methods§

fn read_field( item: &mut InplaceOption<'_, T>, reader: FieldReader<'a, '_, R>, ) -> Result<(), Error>

Reads a field into item.

fn default_field(item: &mut InplaceOption<'_, T>) -> Result<(), Error>

Instantiates item with its default value, if there is one.

If an implementation returns Ok(()), then it must have set an item. Callers of this method may panic otherwise.

Provided Methods§

fn packed<'p, C>() -> Option<&'p dyn PackedDecode<'a, T, C>>
where C: CopyExtend<T>, T: 'p,

Unless packed()::must_pack() is true, the sequence decoder must detect the encoding (packed or not) and call the appropriate method.

fn wrap_in_sequence() -> bool

Returns whether this field is wrapped in a message when encoded nested in a sequence (such as a repeated field).

fn read_field_in_sequence( item: &mut InplaceOption<'_, T>, reader: FieldReader<'a, '_, R>, ) -> Result<(), Error>

Reads this field that was encoded as part of a sequence, unwrapping it from a message if necessary.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<'a, 'b, R> FieldDecode<'a, Cow<'b, str>, R> for OwningCowField

§

impl<'a, 'b, R> FieldDecode<'a, Cow<'b, [u8]>, R> for OwningCowField

§

impl<'a, K, V, T, EK, EV, R> FieldDecode<'a, T, R> for MapField<K, V, EK, EV>
where T: Default + Extend<(K, V)>, EK: FieldDecode<'a, K, R>, EV: FieldDecode<'a, V, R>,

§

impl<'a, R> FieldDecode<'a, Cow<'a, str>, R> for BorrowedCowField

§

impl<'a, R> FieldDecode<'a, Cow<'a, [u8]>, R> for BorrowedCowField

§

impl<'a, R> FieldDecode<'a, u8, R> for ByteField

§

impl<'a, T, R> FieldDecode<'a, T, R> for BytesField
where T: From<&'a [u8]> + Default,

§

impl<'a, T, R> FieldDecode<'a, T, R> for Fixed32Field
where T: FixedNumber<Type = u32>,

§

impl<'a, T, R> FieldDecode<'a, T, R> for Fixed64Field
where T: FixedNumber<Type = u64>,

§

impl<'a, T, R> FieldDecode<'a, T, R> for SignedVarintField
where T: FromNumber,

§

impl<'a, T, R> FieldDecode<'a, T, R> for StringField
where T: From<&'a str> + Default,

§

impl<'a, T, R> FieldDecode<'a, T, R> for VarintField
where T: FromNumber,

§

impl<'a, T, R> FieldDecode<'a, T, R> for ZeroCopyEncoding
where T: FromBytes + Immutable + KnownLayout,

§

impl<'a, T, R, E> FieldDecode<'a, Option<T>, R> for OptionField<E>
where E: FieldDecode<'a, T, R>,

§

impl<'a, T, R, E> FieldDecode<'a, Box<T>, R> for BoxEncoding<E>
where E: FieldDecode<'a, T, R>,

§

impl<'a, T, R, E> FieldDecode<'a, Arc<T>, R> for ArcEncoding<E>
where T: Clone, E: FieldDecode<'a, T, R>,

§

impl<'a, T, R, E> FieldDecode<'a, Vec<T>, R> for VecField<E>
where E: FieldDecode<'a, T, R>,

§

impl<'a, T, R, E> FieldDecode<'a, T, R> for MessageEncoding<E>
where E: MessageDecode<'a, T, R>,

§

impl<'a, T, R, E, const N: usize> FieldDecode<'a, [T; N], R> for ArrayField<E>
where E: FieldDecode<'a, T, R>,

§

impl<'de, T, E, R> FieldDecode<'de, T, R> for TransparentEncoding<E>
where T: Transparent, E: FieldDecode<'de, <T as Transparent>::Inner, R>,

§

const ENTRY: DecoderEntry<'de, T, R>

§

impl<'de, T, R> FieldDecode<'de, T, R> for OneofEncoder
where T: OneofDecode<'de, R>,

§

impl<'de, T, R> FieldDecode<'de, T, R> for TableEncoder
where T: StructDecodeMetadata<'de, R>,

§

const ENTRY: DecoderEntry<'de, T, R>

§

impl<R> FieldDecode<'_, Ipv6Addr, R> for Ipv6AddrField

§

impl<T, R> FieldDecode<'_, T, R> for PortField
where T: From<Port>, Port: TryFrom<R>, <Port as TryFrom<R>>::Error: 'static + Error + Send + Sync,

§

impl<T, R> FieldDecode<'_, T, R> for IgnoreField
where T: Default,

§

impl<T, R> FieldDecode<'_, T, R> for ImpossibleField

§

impl<T, R> FieldDecode<'_, T, R> for U128LittleEndianField
where T: From<u128>,

§

impl<T, U, R> FieldDecode<'_, T, R> for ResourceField<U>
where T: From<U>, U: TryFrom<R>, <U as TryFrom<R>>::Error: 'static + Error + Send + Sync,