# clawhdf5-derive `#[derive(H5Type)]`: maps a Rust struct with named fields to an HDF5 compound datatype. The derive generates three inherent methods: - `hdf5_datatype() -> clawhdf5_format::datatype::Datatype` — the `Datatype::Compound` (members in field order, packed, little-endian); - `to_bytes(&self) -> Vec` — one element in that layout; - `from_bytes(&[u8]) -> Self` — the reverse (panics if the slice is shorter than the compound). Supported field types: `f32`, `f64`, `i8`–`i64`, `u8`–`u64`, `bool` (stored as `u8`) and fixed-size arrays `[T; N]` of those numeric types. Tuple structs, enums and nested structs are refused at compile time. The generated code names `clawhdf5_format`, so the crate using the derive must depend on [`clawhdf5-format`](../clawhdf5-format/README.md) too. Not on crates.io yet: ```toml [dependencies] clawhdf5-derive = { git = "https://git.redclaw.dev/quantumclaw/clawhdf5" } clawhdf5-format = { git = "https://git.redclaw.dev/quantumclaw/clawhdf5" } ``` ## Example ```rust use clawhdf5_derive::H5Type; use clawhdf5_format::datatype::Datatype; #[derive(H5Type, Debug, PartialEq)] struct Point { id: u32, pos: [f64; 3], valid: bool, } let p = Point { id: 7, pos: [1.0, 2.0, 3.0], valid: true }; let bytes = p.to_bytes(); assert_eq!(bytes.len(), 4 + 24 + 1); assert_eq!(Point::from_bytes(&bytes), p); assert!(matches!(Point::hdf5_datatype(), Datatype::Compound { size: 29, .. })); ``` Tests: `crates/clawhdf5-format/tests/derive_tests.rs`. ## License MIT