#offset #offset-of #mem #ffi

no-std dev testaso

Test alignment, size and offset for structs

1 unstable release

0.1.0 Mar 25, 2022

#196 in No standard library

Download history 302/week @ 2023-11-27 200/week @ 2023-12-04 705/week @ 2023-12-11 96/week @ 2023-12-18 17/week @ 2023-12-25 5/week @ 2024-01-01 13/week @ 2024-01-08 177/week @ 2024-01-15 112/week @ 2024-01-22 225/week @ 2024-01-29 150/week @ 2024-02-05 49/week @ 2024-02-12 154/week @ 2024-02-19 547/week @ 2024-02-26 189/week @ 2024-03-04 107/week @ 2024-03-11

1,001 downloads per month
Used in 4 crates

MIT license

9KB
114 lines

lint enarxbot Workflow Status Average time to resolve an issue Percentage of issues still open Maintenance

testaso

Macro to test alignment, size and offsets of structs

This is mostly useful for creating FFI structures.

The crucial field offset calculation was extracted from the memoffset crate. Kudos to Gilad Naaman and Ralf Jung and all the other contributors.

Examples

#[repr(C)]
struct Simple {
    a: u32,
    b: [u8; 2],
    c: i64,
}

#[repr(C, packed)]
struct SimplePacked {
    a: u32,
    b: [u8; 2],
    c: i64,
}

#[cfg(test)]
mod test {
    use testaso::testaso;

    use super::Simple;
    use super::SimplePacked;

    testaso! {
        struct Simple: 8, 16 => {
            a: 0,
            b: 4,
            c: 8
        }

        struct SimplePacked: 1, 14 => {
            a: 0,
            b: 4,
            c: 6
        }
    }
}

License: MIT

No runtime deps