[−][src]Struct bufsize::SizeCounter
Implementation of BufMut
to count the size of a resulting buffer.
This effectively requires the data to be serialized twice, but in many use cases inlining allows most of the effort of generating actual data to be elided.
Example
use bufsize::SizeCounter; use bytes::BufMut; pub struct DataStructure; impl DataStructure { pub fn serialize<B: BufMut>(&self, buf: &mut B) { let name = "DataStructure"; buf.put_u8(name.len() as u8); buf.put_slice(name.as_bytes()); buf.put_u32_le(9999); buf.put_f32_le(1.0); } } fn main() { let mut sizecount = SizeCounter::new(); DataStructure.serialize(&mut sizecount); let mut buffer = Vec::with_capacity(sizecount.size()); DataStructure.serialize(&mut buffer); assert_eq!(sizecount.size(), buffer.len()); }
Methods
impl SizeCounter
[src]
Trait Implementations
impl Debug for SizeCounter
[src]
impl BufMut for SizeCounter
[src]
fn remaining_mut(&self) -> usize
[src]
unsafe fn advance_mut(&mut self, cnt: usize)
[src]
unsafe fn bytes_mut(&mut self) -> &mut [u8]
[src]
fn has_remaining_mut(&self) -> bool
[src]
fn put<T: IntoBuf>(&mut self, src: T) where
Self: Sized,
[src]
Self: Sized,
fn put_slice(&mut self, src: &[u8])
[src]
fn put_u8(&mut self, n: u8)
[src]
fn put_i8(&mut self, n: i8)
[src]
fn put_u16_be(&mut self, n: u16)
[src]
fn put_u16_le(&mut self, n: u16)
[src]
fn put_i16_be(&mut self, n: i16)
[src]
fn put_i16_le(&mut self, n: i16)
[src]
fn put_u32_be(&mut self, n: u32)
[src]
fn put_u32_le(&mut self, n: u32)
[src]
fn put_i32_be(&mut self, n: i32)
[src]
fn put_i32_le(&mut self, n: i32)
[src]
fn put_u64_be(&mut self, n: u64)
[src]
fn put_u64_le(&mut self, n: u64)
[src]
fn put_i64_be(&mut self, n: i64)
[src]
fn put_i64_le(&mut self, n: i64)
[src]
fn put_uint_be(&mut self, n: u64, nbytes: usize)
[src]
fn put_uint_le(&mut self, n: u64, nbytes: usize)
[src]
fn put_int_be(&mut self, n: i64, nbytes: usize)
[src]
fn put_int_le(&mut self, n: i64, nbytes: usize)
[src]
fn put_f32_be(&mut self, n: f32)
[src]
fn put_f32_le(&mut self, n: f32)
[src]
fn put_f64_be(&mut self, n: f64)
[src]
fn put_f64_le(&mut self, n: f64)
[src]
unsafe fn bytes_vec_mut(&'a mut self, dst: &mut [&'a mut IoVec]) -> usize
[src]
fn by_ref(&mut self) -> &mut Self
[src]
fn writer(self) -> Writer<Self>
[src]
Auto Trait Implementations
impl Send for SizeCounter
impl Sync for SizeCounter
impl Unpin for SizeCounter
impl UnwindSafe for SizeCounter
impl RefUnwindSafe for SizeCounter
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,