Skip to main content

Extension

Struct Extension 

Source
pub struct Extension<C: ExtensionCodec> { /* private fields */ }
Expand description

Typed extension descriptor.

Emitted by codegen as a pub const for each extend declaration. The type parameter C is an ExtensionCodec — a zero-sized codec struct that encodes the proto field type. Users don’t name C directly; it flows through inference from the const to the ExtensionSet method call.

For proto2 extensions declared with [default = ...], codegen stores a function pointer that lazily produces the default value. See Extension::with_default and ExtensionSet::extension_or_default.

Implementations§

Source§

impl<C: ExtensionCodec> Extension<C>

Source

pub const fn new(number: u32, extendee: &'static str) -> Self

Construct an extension descriptor for the given field number and extendee message.

const fn so that generated pub const items can use it.

extendee is the fully-qualified proto type name (no leading dot) of the message this extension extends — e.g. "google.protobuf.FieldOptions". Passing an extension with a mismatched extendee to extension() / set_extension() / clear_extension() will panic.

Field number 0 is invalid in protobuf. Codegen never emits it; a descriptor constructed with 0 will never match valid wire data.

Source

pub const fn with_default( number: u32, extendee: &'static str, default: fn() -> C::Value, ) -> Self

Construct an extension descriptor with a proto2 [default = ...] value.

The default is returned by ExtensionSet::extension_or_default when the extension is absent. ExtensionSet::extension continues to return None when absent — this is additive, not a semantic change.

The function pointer is called lazily on each extension_or_default call. For Copy scalars codegen emits a const fn; for String and bytes a regular fn (allocates on each call — same cost as a hand-written .unwrap_or_else(|| "x".into())).

Source

pub const fn number(&self) -> u32

The extension’s field number on the extendee.

Source

pub const fn extendee(&self) -> &'static str

The fully-qualified proto name of the extendee message.

Trait Implementations§

Source§

impl<C: ExtensionCodec> Clone for Extension<C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + ExtensionCodec> Debug for Extension<C>
where C::Value: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: ExtensionCodec> Copy for Extension<C>

Auto Trait Implementations§

§

impl<C> Freeze for Extension<C>

§

impl<C> RefUnwindSafe for Extension<C>

§

impl<C> Send for Extension<C>

§

impl<C> Sync for Extension<C>

§

impl<C> Unpin for Extension<C>

§

impl<C> UnsafeUnpin for Extension<C>

§

impl<C> UnwindSafe for Extension<C>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.