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§type Error = Infallible
type Error = Infallible
The error type returned by all encoding operations. Read more
Source§impl ByteEncoder for SizeEncoder
impl ByteEncoder for SizeEncoder
Source§impl Clone for SizeEncoder
impl Clone for SizeEncoder
Source§fn clone(&self) -> SizeEncoder
fn clone(&self) -> SizeEncoder
Returns a duplicate 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 Debug for SizeEncoder
impl Debug for SizeEncoder
Source§impl Default for SizeEncoder
impl Default for SizeEncoder
Source§fn default() -> SizeEncoder
fn default() -> SizeEncoder
Returns the “default value” for a type. Read more
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
Source§fn cmp(&self, other: &SizeEncoder) -> Ordering
fn cmp(&self, other: &SizeEncoder) -> Ordering
1.21.0 · 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
Source§impl PartialEq for SizeEncoder
impl PartialEq for SizeEncoder
Source§impl PartialOrd for SizeEncoder
impl PartialOrd for SizeEncoder
Source§impl Write for SizeEncoder
impl Write for SizeEncoder
impl Copy for SizeEncoder
impl Eq 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 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