pub struct MessageView<'a> {
pub header: Header,
pub query: &'a [u8],
pub body: &'a [u8],
}Expand description
Borrowing view over a serialized REPE message.
Unlike Message::from_slice, which copies the query and body out of the
caller’s buffer, MessageView keeps both as borrowed slices of the input.
Useful when a large body (e.g. a multi-MiB chunk) will be deserialized with
serde_bytes::Bytes<'a> so the bulk payload stays borrowed end-to-end.
The header is decoded by value because it’s only 48 bytes and downstream
code typically wants the parsed fields rather than the raw header bytes.
Fields§
§header: Header§query: &'a [u8]§body: &'a [u8]Implementations§
Source§impl<'a> MessageView<'a>
impl<'a> MessageView<'a>
Sourcepub fn from_slice(buf: &'a [u8]) -> Result<Self, RepeError>
pub fn from_slice(buf: &'a [u8]) -> Result<Self, RepeError>
Parse a MessageView from buf. The returned view borrows from buf;
no copies are made.
Sourcepub fn from_slice_exact(buf: &'a [u8]) -> Result<Self, RepeError>
pub fn from_slice_exact(buf: &'a [u8]) -> Result<Self, RepeError>
Like from_slice but rejects trailing bytes: errors
if buf is longer than the framed message. The borrowing counterpart of
Message::from_slice_exact, for transports (e.g. a WebSocket binary
frame) that carry exactly one message per buffer.
Sourcepub fn query_str(&self) -> Result<&'a str, Utf8Error>
pub fn query_str(&self) -> Result<&'a str, Utf8Error>
View the query as a &str. Errors if the query is not valid UTF-8.
Sourcepub fn to_message(&self) -> Message
pub fn to_message(&self) -> Message
Copy this borrowed view into an owned Message, allocating the query
and body. Used as the fallback for HandlerErased::handle_view when a
handler has not overridden the borrowing path.
Trait Implementations§
Source§impl<'a> Clone for MessageView<'a>
impl<'a> Clone for MessageView<'a>
Source§fn clone(&self) -> MessageView<'a>
fn clone(&self) -> MessageView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for MessageView<'a>
Source§impl<'a> Debug for MessageView<'a>
impl<'a> Debug for MessageView<'a>
impl<'a> Eq for MessageView<'a>
Source§impl<'a> PartialEq for MessageView<'a>
impl<'a> PartialEq for MessageView<'a>
Source§fn eq(&self, other: &MessageView<'a>) -> bool
fn eq(&self, other: &MessageView<'a>) -> bool
self and other values to be equal, and is used by ==.