Struct packet::serialize::TruncatingSerializer
source · 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_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 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