pub trait MessageView<'a>: Sized {
type Owned: Message;
// Required methods
fn decode_view(buf: &'a [u8]) -> Result<Self, DecodeError>;
fn to_owned_message(&self) -> Self::Owned;
// Provided method
fn decode_view_with_limit(
buf: &'a [u8],
_depth: u32,
) -> Result<Self, DecodeError> { ... }
}Expand description
Trait for zero-copy borrowed message views.
View types borrow from the input buffer and provide read-only access
to message fields without allocation. Each generated MyMessageView<'a>
implements this trait.
The lifetime 'a ties the view to the input buffer — the view cannot
outlive the buffer it was decoded from.
Required Associated Types§
Required Methods§
Sourcefn decode_view(buf: &'a [u8]) -> Result<Self, DecodeError>
fn decode_view(buf: &'a [u8]) -> Result<Self, DecodeError>
Decode a view from a buffer, borrowing string/bytes fields directly.
The returned view borrows from buf’s underlying bytes. The caller
must ensure the buffer is contiguous (e.g., &[u8] or bytes::Bytes).
Sourcefn to_owned_message(&self) -> Self::Owned
fn to_owned_message(&self) -> Self::Owned
Convert this view to the owned message type.
This allocates and copies all borrowed fields.
Provided Methods§
Sourcefn decode_view_with_limit(
buf: &'a [u8],
_depth: u32,
) -> Result<Self, DecodeError>
fn decode_view_with_limit( buf: &'a [u8], _depth: u32, ) -> Result<Self, DecodeError>
Decode a view with a custom recursion depth limit.
Used by DecodeOptions::decode_view
to pass a non-default recursion budget. The default implementation
delegates to decode_view (ignoring the limit);
generated code overrides this to call _decode_depth(buf, depth).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.