Skip to main content

UnknownFieldsView

Struct UnknownFieldsView 

Source
pub struct UnknownFieldsView<'a> { /* private fields */ }
Expand description

A borrowed view of unknown fields.

Stores raw byte slices from the input buffer rather than decoded values, enabling zero-copy round-tripping of unknown fields. Each stored span holds one or more consecutive complete (tag, value) records: adjacent unknown fields are coalesced into a single span, so a long run of unknown fields costs one Vec slot rather than one per field. Coalescing bounds the view’s memory only — the decode-time unknown-field allowance is still charged per field (see push_record).

Implementations§

Source§

impl<'a> UnknownFieldsView<'a>

Source

pub fn new() -> Self

Creates an empty view.

Source

pub fn is_empty(&self) -> bool

Returns true if no unknown fields were recorded.

Source

pub fn encoded_len(&self) -> usize

Total byte length of all unknown field data.

Source

pub fn write_to(&self, buf: &mut impl BufMut)

Write all unknown-field bytes verbatim. Each span holds one or more complete (tag, value) records as they appeared on the wire, so concatenating the spans produces a valid encoding.

Source

pub fn to_owned(&self) -> Result<UnknownFields, DecodeError>

Convert to an owned UnknownFields by parsing all stored raw byte spans.

Each span holds one or more consecutive (tag + value) records as they appeared on the wire. Parsing uses crate::encoding::decode_unknown_field under exactly the budget push_record charged at decode time — the same field count and group-nesting depth — so replay cannot exhaust either. Views holding manually pushed spans (via push_raw) additionally get DEFAULT_UNKNOWN_FIELD_LIMIT slots and the full RECURSION_LIMIT, since those spans were never charged. A coalesced span re-materializes one owned UnknownField per record, so this conversion is where a long run of unknown fields actually allocates.

§Errors

Returns Err if a stored span is malformed or exceeds the replay budget. Neither can occur when the view was produced by wire decoding — every span was parsed off the wire, and the budget equals what decoding charged — so any view that decoded successfully converts successfully. Only views holding push_raw spans can fail here.

Trait Implementations§

Source§

impl<'a> Clone for UnknownFieldsView<'a>

Source§

fn clone(&self) -> UnknownFieldsView<'a>

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 Debug for UnknownFieldsView<'_>

Source§

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

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

impl<'a> Default for UnknownFieldsView<'a>

Source§

fn default() -> UnknownFieldsView<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for UnknownFieldsView<'a>

§

impl<'a> RefUnwindSafe for UnknownFieldsView<'a>

§

impl<'a> Send for UnknownFieldsView<'a>

§

impl<'a> Sync for UnknownFieldsView<'a>

§

impl<'a> Unpin for UnknownFieldsView<'a>

§

impl<'a> UnsafeUnpin for UnknownFieldsView<'a>

§

impl<'a> UnwindSafe for UnknownFieldsView<'a>

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.