Trait mesh_protobuf::FieldEncode

source ·
pub trait FieldEncode<T, R>: Sized {
    const ENTRY: EncoderEntry<T, R> = _;

    // Required methods
    fn write_field(item: T, writer: FieldWriter<'_, '_, R>);
    fn compute_field_size(item: &mut T, sizer: FieldSizer<'_>);

    // Provided methods
    fn packed<'a>() -> Option<&'a dyn PackedEncode<T>>
       where T: 'a { ... }
    fn wrap_in_sequence() -> bool { ... }
    fn write_field_in_sequence(item: T, writer: &mut SequenceWriter<'_, '_, R>) { ... }
    fn compute_field_size_in_sequence(
        item: &mut T,
        sizer: &mut SequenceSizer<'_>,
    ) { ... }
}
Expand description

The FieldEncode trait provides a field encoder for type T.

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

Provided Associated Constants§

source

const ENTRY: EncoderEntry<T, R> = _

The table encoder entry for this type, used in types from table::encode.

This should not be overridden by implementations.

Required Methods§

source

fn write_field(item: T, writer: FieldWriter<'_, '_, R>)

Writes item as a field.

source

fn compute_field_size(item: &mut T, sizer: FieldSizer<'_>)

Computes the size of item as a field.

Encoding will panic if the write_field call writes a different number of bytes than computed by this call.

Takes a mut reference to allow mutating/stabilizing the value so that the subsequence call to write_field acts on the same value as this call.

Provided Methods§

source

fn packed<'a>() -> Option<&'a dyn PackedEncode<T>>
where T: 'a,

Returns the encoder for writing multiple instances of this field in a packed list, or None if there is no packed encoding for this type.

source

fn wrap_in_sequence() -> bool

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

This is necessary to avoid ambiguity between the repeated inner and outer values.

source

fn write_field_in_sequence(item: T, writer: &mut SequenceWriter<'_, '_, R>)

Writes this field as part of a sequence, wrapping it in a message if necessary.

source

fn compute_field_size_in_sequence(item: &mut T, sizer: &mut SequenceSizer<'_>)

Computes the size of this field as part of a sequence, including the size of a wrapping message.

Object Safety§

This trait is not object safe.

Implementors§

source§

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

source§

impl<'a, R> FieldEncode<Cow<'a, str>, R> for OwningCowField

source§

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

source§

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

source§

impl<K, V, T, EK, EV, R> FieldEncode<T, R> for MapField<K, V, EK, EV>
where T: IntoIterator<Item = (K, V)>, for<'a> &'a mut T: IntoIterator<Item = (&'a K, &'a mut V)>, for<'a> EK: FieldEncode<&'a K, R>, EV: FieldEncode<V, R>,

source§

impl<R> FieldEncode<u8, R> for ByteField

source§

impl<R> FieldEncode<u128, R> for U128LittleEndianField

source§

impl<T, R> FieldEncode<T, R> for ImpossibleField

source§

impl<T, R> FieldEncode<T, R> for TableEncoder

source§

const ENTRY: EncoderEntry<T, R> = _

source§

impl<T, R, E: FieldEncode<T, R>> FieldEncode<Option<T>, R> for OptionField<E>

source§

impl<T, R, E: FieldEncode<T, R>> FieldEncode<Box<T>, R> for BoxEncoding<E>

source§

impl<T, R, E: FieldEncode<T, R>> FieldEncode<Vec<T>, R> for VecField<E>

source§

impl<T, R, E: FieldEncode<T, R>, const N: usize> FieldEncode<[T; N], R> for ArrayField<E>

source§

impl<T, R, E: MessageEncode<T, R>> FieldEncode<T, R> for MessageEncoding<E>

source§

impl<T, U, R> FieldEncode<T, R> for ResourceField<U>
where T: Into<U>, U: Into<R>,

source§

impl<T: FixedNumber<Type = u32>, R> FieldEncode<T, R> for Fixed32Field

source§

impl<T: FixedNumber<Type = u64>, R> FieldEncode<T, R> for Fixed64Field

source§

impl<T: ToNumber, R> FieldEncode<T, R> for SignedVarintField

source§

impl<T: ToNumber, R> FieldEncode<T, R> for VarintField

source§

impl<T: Clone, R, E: FieldEncode<T, R>> FieldEncode<Arc<T>, R> for ArcEncoding<E>

source§

impl<T: AsRef<str>, R> FieldEncode<T, R> for StringField

source§

impl<T: AsRef<[u8]>, R> FieldEncode<T, R> for BytesField

source§

impl<T: Default, R> FieldEncode<T, R> for IgnoreField

source§

impl<T: OneofEncode<R>, R> FieldEncode<T, R> for OneofEncoder

source§

impl<T: Transparent, E: FieldEncode<T::Inner, R>, R> FieldEncode<T, R> for TransparentEncoding<E>

source§

const ENTRY: EncoderEntry<T, R> = _

source§

impl<T: AsBytes, R> FieldEncode<T, R> for ZeroCopyEncoding