#mem #offset #offset-of #offsetof #ffi

no-std dev testaso

Test alignment, size and offset for structs

1 unstable release

0.1.0 Mar 25, 2022

#91 in No standard library

Download history 409/week @ 2022-06-13 842/week @ 2022-06-20 1362/week @ 2022-06-27 1635/week @ 2022-07-04 1388/week @ 2022-07-11 2420/week @ 2022-07-18 937/week @ 2022-07-25 2667/week @ 2022-08-01 822/week @ 2022-08-08 518/week @ 2022-08-15 436/week @ 2022-08-22 1721/week @ 2022-08-29 1327/week @ 2022-09-05 1929/week @ 2022-09-12 4648/week @ 2022-09-19 1193/week @ 2022-09-26

9,098 downloads per month
Used in 4 crates

MIT license

8KB
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