Crates.io | bufsize |
lib.rs | bufsize |
version | |
source | src |
created_at | 2019-10-09 05:16:03.853306 |
updated_at | 2024-11-13 23:58:49.910754 |
description | bytes::BufMut implementation to count buffer size |
homepage | |
repository | https://github.com/dtolnay/bufsize |
max_upload_size | |
id | 171134 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This library provides an implementation of bytes::BufMut
to count the size
of a resulting buffer.
[dependencies]
bufsize = "1.0"
Compiler support: requires rustc 1.39+
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());
}