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>
impl<V> MessageFieldView<V>
Sourcepub fn some(v: V) -> Self
pub fn some(v: V) -> Self
Alias for set, mirroring owned
MessageField::some.
Source§impl<'a, V: ViewEncode<'a>> MessageFieldView<V>
impl<'a, V: ViewEncode<'a>> MessageFieldView<V>
Sourcepub fn compute_size(&self, cache: &mut SizeCache) -> u32
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.
Trait Implementations§
Source§impl<V: Clone> Clone for MessageFieldView<V>
impl<V: Clone> Clone for MessageFieldView<V>
Source§fn clone(&self) -> MessageFieldView<V>
fn clone(&self) -> MessageFieldView<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<V: Debug> Debug for MessageFieldView<V>
impl<V: Debug> Debug for MessageFieldView<V>
Source§impl<V> Default for MessageFieldView<V>
impl<V> Default for MessageFieldView<V>
Source§impl<V: DefaultViewInstance> Deref for MessageFieldView<V>
impl<V: DefaultViewInstance> Deref for MessageFieldView<V>
Source§impl<V> From<V> for MessageFieldView<V>
impl<V> From<V> for MessageFieldView<V>
Source§impl<V: PartialEq + DefaultViewInstance> PartialEq for MessageFieldView<V>
Wire-equivalent equality: Unset equals Set(v) when v equals the
default instance.
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.