#[non_exhaustive]pub enum WireBytes<'a> {
InBuffer,
Own(&'a [u8]),
}Expand description
Where a Serialized value’s bytes are: in the buffer it was handed, or in the value
itself.
It is the answer Serialized::wire_bytes gives, and the publish path needs it because the
two are not interchangeable underneath: a transport that keeps the payload takes the buffer
where the value wrote into it, and copies where the bytes belong to the value. A pointer
comparison would guess at the same fact; this states it.
§Examples
use std::convert::Infallible;
use ruststream::prelude::*;
/// A frame that already holds its encoded bytes: it lends them, and the buffer it was handed
/// stays untouched.
struct Frame(Vec<u8>);
impl Serialized for Frame {
type Error = Infallible;
fn wire_bytes(&self, _buf: &mut BytesMut) -> Result<WireBytes<'_>, Infallible> {
Ok(WireBytes::Own(&self.0))
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
InBuffer
The value wrote its bytes into the buffer it was handed.
Own(&'a [u8])
The bytes are the value’s own, lent for the length of the publish.
Implementations§
Source§impl<'a> WireBytes<'a>
impl<'a> WireBytes<'a>
Sourcepub fn of(self, buf: &'a BytesMut) -> &'a [u8] ⓘ
pub fn of(self, buf: &'a BytesMut) -> &'a [u8] ⓘ
The bytes themselves, given the buffer the value was handed.
What a caller that only reads them uses; the publish path answers the two arms differently, because only one of them can be taken.
§Examples
use ruststream::BytesMut;
use ruststream::runtime::Serialized;
/// The size a value has on the wire, for a check against the broker's payload limit before
/// the publish is attempted.
fn wire_len<T: Serialized>(value: &T) -> Result<usize, T::Error> {
let mut buf = BytesMut::new();
Ok(value.wire_bytes(&mut buf)?.of(&buf).len())
}Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for WireBytes<'a>
impl<'a> RefUnwindSafe for WireBytes<'a>
impl<'a> Send for WireBytes<'a>
impl<'a> Sync for WireBytes<'a>
impl<'a> Unpin for WireBytes<'a>
impl<'a> UnsafeUnpin for WireBytes<'a>
impl<'a> UnwindSafe for WireBytes<'a>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more