pub struct TruncatingSerializer<B> { /* private fields */ }
Expand description
A Serializer
that truncates its body if it would exceed a size limit.
TruncatingSerializer
wraps a buffer, and implements Serializer
. Unlike
the blanket impl of Serializer
for B: GrowBuffer + ShrinkBuffer
, if the
buffer’s body exceeds the size limit constraint passed to
Serializer::serialize
, the body is truncated to fit.
Note that this does not guarantee that size limit exceeded errors will not occur. The size limit may be small enough that the encapsulating headers alone exceed the size limit. There may also be a minimum body length constraint which is larger than the size limit.
Implementations§
Source§impl<B> TruncatingSerializer<B>
impl<B> TruncatingSerializer<B>
Sourcepub fn new(buffer: B, direction: TruncateDirection) -> TruncatingSerializer<B>
pub fn new(buffer: B, direction: TruncateDirection) -> TruncatingSerializer<B>
Constructs a new TruncatingSerializer
.
Trait Implementations§
Source§impl<B: Clone> Clone for TruncatingSerializer<B>
impl<B: Clone> Clone for TruncatingSerializer<B>
Source§fn clone(&self) -> TruncatingSerializer<B>
fn clone(&self) -> TruncatingSerializer<B>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<B: Debug> Debug for TruncatingSerializer<B>
impl<B: Debug> Debug for TruncatingSerializer<B>
Source§impl<B: GrowBuffer + ShrinkBuffer> Serializer for TruncatingSerializer<B>
impl<B: GrowBuffer + ShrinkBuffer> Serializer for TruncatingSerializer<B>
Source§fn serialize<BB: GrowBufferMut, P: BufferProvider<B, BB>>(
self,
outer: PacketConstraints,
provider: P,
) -> Result<BB, (SerializeError<P::Error>, Self)>
fn serialize<BB: GrowBufferMut, P: BufferProvider<B, BB>>( self, outer: PacketConstraints, provider: P, ) -> Result<BB, (SerializeError<P::Error>, Self)>
Serializes this
Serializer
, producing a buffer. Read moreSource§fn serialize_new_buf<BB: ReusableBuffer, A: BufferAlloc<BB>>(
&self,
outer: PacketConstraints,
alloc: A,
) -> Result<BB, SerializeError<A::Error>>
fn serialize_new_buf<BB: ReusableBuffer, A: BufferAlloc<BB>>( &self, outer: PacketConstraints, alloc: A, ) -> Result<BB, SerializeError<A::Error>>
Serializes the data into a new buffer without consuming
self
. Read moreSource§fn serialize_vec(
self,
outer: PacketConstraints,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_vec(
self,
outer: PacketConstraints,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
Serializes this
Serializer
, allocating a Buf<Vec<u8>>
if the
contained buffer isn’t large enough. Read moreSource§fn serialize_no_alloc(
self,
outer: PacketConstraints,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_no_alloc(
self,
outer: PacketConstraints,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
Serializes this
Serializer
, failing if the existing buffer is not
large enough. Read moreSource§fn serialize_outer<B: GrowBufferMut, P: BufferProvider<Self::Buffer, B>>(
self,
provider: P,
) -> Result<B, (SerializeError<P::Error>, Self)>
fn serialize_outer<B: GrowBufferMut, P: BufferProvider<Self::Buffer, B>>( self, provider: P, ) -> Result<B, (SerializeError<P::Error>, Self)>
Serializes this
Serializer
as the outermost packet. Read moreSource§fn serialize_vec_outer(
self,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_vec_outer(
self,
) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where
Self::Buffer: ReusableBuffer,
Serializes this
Serializer
as the outermost packet, allocating a
Buf<Vec<u8>>
if the contained buffer isn’t large enough. Read moreSource§fn serialize_no_alloc_outer(
self,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
fn serialize_no_alloc_outer(
self,
) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where
Self::Buffer: ReusableBuffer,
Serializes this
Serializer
as the outermost packet, failing if the
existing buffer is not large enough. Read moreSource§fn encapsulate<B>(self, outer: B) -> Nested<Self, B>
fn encapsulate<B>(self, outer: B) -> Nested<Self, B>
Source§fn with_size_limit(self, limit: usize) -> Nested<Self, LimitedSizePacketBuilder>
fn with_size_limit(self, limit: usize) -> Nested<Self, LimitedSizePacketBuilder>
Creates a new
Serializer
which will enforce a size limit. Read moreimpl<B: Copy> Copy for TruncatingSerializer<B>
Auto Trait Implementations§
impl<B> Freeze for TruncatingSerializer<B>where
B: Freeze,
impl<B> RefUnwindSafe for TruncatingSerializer<B>where
B: RefUnwindSafe,
impl<B> Send for TruncatingSerializer<B>where
B: Send,
impl<B> Sync for TruncatingSerializer<B>where
B: Sync,
impl<B> Unpin for TruncatingSerializer<B>where
B: Unpin,
impl<B> UnwindSafe for TruncatingSerializer<B>where
B: UnwindSafe,
Blanket Implementations§
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)