Skip to main content

ExtensionSet

Trait ExtensionSet 

Source
pub trait ExtensionSet {
    const PROTO_FQN: &'static str;

    // Required methods
    fn unknown_fields(&self) -> &UnknownFields;
    fn unknown_fields_mut(&mut self) -> &mut UnknownFields;

    // Provided methods
    fn extension<C: ExtensionCodec>(&self, ext: &Extension<C>) -> C::Output { ... }
    fn set_extension<C: ExtensionCodec>(
        &mut self,
        ext: &Extension<C>,
        value: C::Value,
    ) { ... }
    fn has_extension<C: ExtensionCodec>(&self, ext: &Extension<C>) -> bool { ... }
    fn clear_extension<C: ExtensionCodec>(&mut self, ext: &Extension<C>) { ... }
    fn extension_or_default<C>(&self, ext: &Extension<C>) -> C::Value
       where C: ExtensionCodec<Output = Option<<C as ExtensionCodec>::Value>>,
             C::Value: Default { ... }
}
Expand description

Implemented by codegen on every message that preserves unknown fields.

The only required methods are the two unknown_fields* accessors; all extension operations are defaulted on top of them. The generated impl is therefore a two-line body.

Not object-safe (the default methods are generic over C). Extension access is always statically dispatched from a const descriptor.

Required Associated Constants§

Source

const PROTO_FQN: &'static str

Fully-qualified proto type name of this message (no leading dot), e.g. "google.protobuf.FieldOptions".

Checked against Extension::extendee on every extension(), set_extension(), and clear_extension() call. A mismatch panics: passing an extension for the wrong message is a bug in the caller.

Required Methods§

Source

fn unknown_fields(&self) -> &UnknownFields

Immutable access to the extendee’s unknown-field storage.

Source

fn unknown_fields_mut(&mut self) -> &mut UnknownFields

Mutable access to the extendee’s unknown-field storage.

Provided Methods§

Source

fn extension<C: ExtensionCodec>(&self, ext: &Extension<C>) -> C::Output

Read an extension value.

For singular extensions: Option<T>None if absent or if the stored wire data is malformed for this codec. For repeated: Vec<T>.

§Panics

Panics if ext.extendee() does not match Self::PROTO_FQN.

Source

fn set_extension<C: ExtensionCodec>( &mut self, ext: &Extension<C>, value: C::Value, )

Write an extension value, replacing any prior occurrences.

§Panics

Panics if ext.extendee() does not match Self::PROTO_FQN.

Source

fn has_extension<C: ExtensionCodec>(&self, ext: &Extension<C>) -> bool

Returns true if any record at the extension’s field number is present.

Does not check wire-type validity — this is a fast presence test, not a decode. Also does not check extendee identity: asking “is this extension set here” when it can’t extend here has a legitimate answer (false). This matches protobuf-go’s HasExtension and protobuf-es’s hasExtension, both of which return false gracefully on mismatch.

Source

fn clear_extension<C: ExtensionCodec>(&mut self, ext: &Extension<C>)

Remove all records at the extension’s field number.

§Panics

Panics if ext.extendee() does not match Self::PROTO_FQN.

Source

fn extension_or_default<C>(&self, ext: &Extension<C>) -> C::Value
where C: ExtensionCodec<Output = Option<<C as ExtensionCodec>::Value>>, C::Value: Default,

Read a singular extension value, returning the proto2 [default = ...] value if absent, or the type’s Default if no proto default was declared.

Only meaningful for singular codecs (Output = Option<Value>). For repeated codecs use extension — there is no such thing as a repeated default.

Presence is still distinguishable via extension (returns None) or has_extension.

§Panics

Panics if ext.extendee() does not match Self::PROTO_FQN (transitively, via the inner extension() call).

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§