mesh_protobuf

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

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§

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