Crate assert_size_derive

Crate assert_size_derive 

Source
Expand description

Compile-time type size assertions.

This crate provides the assert_size attribute macro for verifying that types have the expected size in bytes at compile time.

§Quick Start

use assert_size_derive::assert_size;

#[assert_size(2)]
struct MyData {
    foo: u8,
    bar: u8,
}

If the size doesn’t match, compilation will fail with a clear error message.

§Use Cases

  • Catching unintended size changes from code refactoring
  • Ensuring types meet specific memory layout requirements for FFI or serialization
  • Documenting expected type sizes for performance-critical code
  • Detecting platform-specific size variations

Attribute Macros§

assert_size
A compile-time assertion that verifies a type has the expected size in bytes.