https://github.com/p-kraszewski/pakr-assert-size
Runtime checks of the size of structures for Rust
https://github.com/p-kraszewski/pakr-assert-size
Last synced: 26 days ago
JSON representation
Runtime checks of the size of structures for Rust
- Host: GitHub
- URL: https://github.com/p-kraszewski/pakr-assert-size
- Owner: p-kraszewski
- License: bsd-2-clause
- Created: 2021-12-05T13:27:33.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-05T13:55:50.000Z (almost 4 years ago)
- Last Synced: 2025-10-11T10:46:47.296Z (26 days ago)
- Language: Rust
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Examples
## Success (real size matches expected):
```rust
use pakr_assert_size::*;
#[repr(C, packed)]
#[assert_size(16)]
struct A {
field1: u64,
field2: u64,
}
#[assert_size(24)]
#[repr(C, packed)]
struct B {
field1: u64,
field2: u64,
field3: u64,
}
```
## Failure (real size is 24 bytes, expected is 32 bytes):
```rust
use pakr_assert_size::*;
#[assert_size(32)]
#[repr(C, packed)]
struct C {
field1: u64,
field2: u64,
field3: u64,
}
```
# Examples `assert_size_fits`
## Success (real size fits in expected size):
```rust
use pakr_assert_size::*;
// Exact match
#[repr(C, packed)]
#[assert_size_fits(16)]
struct A {
field1: u64,
field2: u64,
}
// Fits in match
#[assert_size_fits(32)]
#[repr(C, packed)]
struct B {
field1: u64,
field2: u64,
field3: u64,
}
```
## Failure (real size is 24 bytes, exceeding maximum of 16 bytes):
```rust
use pakr_assert_size::*;
#[assert_size_fits(16)]
#[repr(C, packed)]
struct C {
field1: u64,
field2: u64,
field3: u64,
}
```