pub struct SizeEncoder { /* private fields */ }Expand description
An encoder that counts the size of the encoded data.
This encoder is useful for calculating the size of the encoded data without actually encoding it, allowing you to pre-allocate a buffer of the correct size before encoding the data.
Note that this encoder runs all the same encoding logic as any other
encoder, so it will trigger the same side effects that other encoders would
trigger (e.g Allocations). See the Encodable trait for more information
on idempotent encodes.
§Example
use encode::Encodable;
use encode::encoders::SizeEncoder;
let encodable = c"hello, world!";
let mut encoder = SizeEncoder::new();
encodable.encode(&mut encoder).unwrap();
assert_eq!(encoder.size(), 14, "13 bytes from the ASCII string and 1 byte for the null terminator");Implementations§
Source§impl SizeEncoder
impl SizeEncoder
Trait Implementations§
Source§impl BaseEncoder for SizeEncoder
impl BaseEncoder for SizeEncoder
Source§impl ByteEncoder for SizeEncoder
impl ByteEncoder for SizeEncoder
Source§impl Clone for SizeEncoder
impl Clone for SizeEncoder
impl Copy for SizeEncoder
Source§impl Debug for SizeEncoder
impl Debug for SizeEncoder
Source§impl Default for SizeEncoder
impl Default for SizeEncoder
impl Eq for SizeEncoder
Source§impl From<SizeEncoder> for usize
impl From<SizeEncoder> for usize
Source§fn from(encoder: SizeEncoder) -> usize
fn from(encoder: SizeEncoder) -> usize
Converts to this type from the input type.
Source§impl Ord for SizeEncoder
impl Ord for SizeEncoder
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for SizeEncoder
impl PartialEq for SizeEncoder
Source§impl PartialOrd for SizeEncoder
impl PartialOrd for SizeEncoder
impl StructuralPartialEq for SizeEncoder
Auto Trait Implementations§
impl Freeze for SizeEncoder
impl RefUnwindSafe for SizeEncoder
impl Send for SizeEncoder
impl Sync for SizeEncoder
impl Unpin for SizeEncoder
impl UnsafeUnpin for SizeEncoder
impl UnwindSafe for SizeEncoder
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