Skip to main content

MessageFieldView

Struct MessageFieldView 

Source
pub struct MessageFieldView<V> { /* private fields */ }
Expand description

A borrowed view of an optional message field.

Analogous to MessageField<T> but for the view layer. Like MessageField, the inner view is boxed — recursive message types (Foo { NestedMessage { corecursive: Foo } }) would otherwise have infinite size. The box is API-transparent: Deref returns &V, and set() takes V by value.

When V implements DefaultViewInstance, this type implements Deref<Target = V>, returning a reference to a static default instance when the field is unset — making view code identical to owned code for field access:

// Both work the same, regardless of whether `address` is set:
let city = owned_msg.address.city;    // MessageField<Address>
let city = view_msg.address.city;     // MessageFieldView<AddressView>

The lifetime of the contained view type V (e.g. AddressView<'a>) ties this to the input buffer — no separate lifetime parameter is needed here.

Implementations§

Source§

impl<V> MessageFieldView<V>

Source

pub const fn unset() -> Self

An unset field (the default).

Source

pub fn set(v: V) -> Self

A set field with the given view value.

Source

pub fn some(v: V) -> Self

Alias for set, mirroring owned MessageField::some.

Source

pub fn is_set(&self) -> bool

Returns true if the field has a value.

Source

pub fn is_unset(&self) -> bool

Returns true if the field has no value.

Source

pub fn as_option(&self) -> Option<&V>

Get a reference to the inner view, or None if unset.

Source

pub fn as_mut(&mut self) -> Option<&mut V>

Get a mutable reference to the inner view, or None if unset.

Used by generated decode code to merge a second occurrence of a message field into an existing value (proto merge semantics).

Source§

impl<'a, V: ViewEncode<'a>> MessageFieldView<V>

Source

pub fn compute_size(&self, cache: &mut SizeCache) -> u32

Forward to the inner view’s compute_size, or 0 if unset. Generated compute_size calls this for nested-message fields, mirroring MessageField on the owned side.

Source

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

Forward to the inner view’s write_to; no-op if unset.

Trait Implementations§

Source§

impl<V: Clone> Clone for MessageFieldView<V>

Source§

fn clone(&self) -> MessageFieldView<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for MessageFieldView<V>

Source§

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

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

impl<V> Default for MessageFieldView<V>

Source§

fn default() -> Self

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

impl<V: DefaultViewInstance> Deref for MessageFieldView<V>

Source§

type Target = V

The resulting type after dereferencing.
Source§

fn deref(&self) -> &V

Dereferences the value.
Source§

impl<V> From<V> for MessageFieldView<V>

Source§

fn from(v: V) -> Self

Converts to this type from the input type.
Source§

impl<V: PartialEq + DefaultViewInstance> PartialEq for MessageFieldView<V>

Wire-equivalent equality: Unset equals Set(v) when v equals the default instance.

This matches MessageField::eq on the owned side, so view_a == view_b agrees with view_a.to_owned_message() == view_b.to_owned_message().

The comparison against the default routes through the Deref impl.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Eq + DefaultViewInstance> Eq for MessageFieldView<V>

Auto Trait Implementations§

§

impl<V> Freeze for MessageFieldView<V>

§

impl<V> RefUnwindSafe for MessageFieldView<V>
where V: RefUnwindSafe,

§

impl<V> Send for MessageFieldView<V>
where V: Send,

§

impl<V> Sync for MessageFieldView<V>
where V: Sync,

§

impl<V> Unpin for MessageFieldView<V>

§

impl<V> UnsafeUnpin for MessageFieldView<V>

§

impl<V> UnwindSafe for MessageFieldView<V>
where V: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.