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.
Sourcepub fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink)
pub fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink)
Forward to the inner view’s write_to;
no-op if unset.
Trait Implementations§
Source§impl<V: Clone> Clone for MessageFieldView<V>
impl<V: Clone> Clone for MessageFieldView<V>
Source§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>
impl<V: Eq> Eq for MessageFieldView<V>
Source§impl<V> From<V> for MessageFieldView<V>
impl<V> From<V> for MessageFieldView<V>
Source§impl<V: Hash> Hash for MessageFieldView<V>
Hashes presence and the view, as Option<&V> does, so that it agrees with
==, like MessageField’s Hash.
impl<V: Hash> Hash for MessageFieldView<V>
Hashes presence and the view, as Option<&V> does, so that it agrees with
==, like MessageField’s Hash.
Source§impl<V: PartialEq> PartialEq for MessageFieldView<V>
Presence-aware equality, matching MessageField:
two unset fields are equal, two set fields are equal when their views are,
and an unset field never equals a set one, not even one set to the default,
since only the set field is on the wire. Compare *a == *b (needs
DefaultViewInstance) to ignore presence.
impl<V: PartialEq> PartialEq for MessageFieldView<V>
Presence-aware equality, matching MessageField:
two unset fields are equal, two set fields are equal when their views are,
and an unset field never equals a set one, not even one set to the default,
since only the set field is on the wire. Compare *a == *b (needs
DefaultViewInstance) to ignore presence.
view_a == view_b agrees with
view_a.to_owned_message() == view_b.to_owned_message().