| Crates.io | buf_sized |
| lib.rs | buf_sized |
| version | 0.1.1 |
| created_at | 2024-09-18 13:44:03.540197+00 |
| updated_at | 2024-09-18 13:55:47.71105+00 |
| description | Calculate buffer sizes needed by types |
| homepage | |
| repository | https://github.com/PaulmannLighting/buf_sized |
| max_upload_size | |
| id | 1379302 |
| size | 10,649 |
Calculate accumulated buffer sizes of types.
Unlike std::mem::size_of<T>(), this crate calculates the size of the buffer that would be required to serialize the
type without taking alignment into account.
use buf_sized::buf_size;
use buf_sized_derive::BufSized;
#[derive(BufSized)]
struct Data {
header: u8,
num: u128,
payload: [u8; 12],
crc: u32,
}
#[test]
fn test_struct() {
assert_eq!(buf_size::<Data>(), 1 + 16 + 12 + 4);
}
cargo fmtcargo clippy -- -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used -W clippy::cargo