#buffer #size #calculations

buf_sized

Calculate buffer sizes needed by types

2 releases

0.1.1 Sep 18, 2024
0.1.0 Sep 18, 2024

#1149 in Encoding

Download history 242/week @ 2024-09-16 8/week @ 2024-09-23 36/week @ 2024-09-30 2/week @ 2024-10-07 9/week @ 2024-10-14

67 downloads per month

MIT license

10KB
140 lines

buf_sized

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.

Usage

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);
}

Contribution guidelines

  • Use cargo fmt
  • Use cargo clippy -- -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used -W clippy::cargo

lib.rs:

A library for types with a fixed buffer size.

Dependencies

~210KB