# sensor-db-derive
`#[derive(SensorData)]` for [`sensor-db`](https://crates.io/crates/sensor-db),
an append-only sensor database for NOR flash on embedded devices.
This crate is an implementation detail of `sensor-db`'s `derive` feature. Reach
for it through that feature rather than depending on it directly:
```toml
sensor-db = { version = "0.1", features = ["derive"] }
zerocopy = { version = "0.8", features = ["derive"] }
```
```rust
use sensor_db::SensorData;
use sensor_db::zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
#[derive(FromBytes, IntoBytes, KnownLayout, Immutable, SensorData)]
#[sensor(id = 0x01, version = 1)]
#[repr(C)]
struct Temperature {
celsius: f32,
}
```
The macro emits the `SensorData` impl and nothing else. `id` and `version`
accept any constant expression, so the central ID module that actually prevents
collisions works directly (`#[sensor(id = ids::TEMPERATURE)]`); `version`
defaults to the trait's `0`, and `crate = ...` covers a renamed `sensor_db`.
Two things it deliberately does **not** do:
- **It does not emit the zerocopy derives.** A derive macro cannot add
attributes to the item it is applied to, and zerocopy's derives expand to
absolute `::zerocopy::` paths — so a re-export does not reach a downstream
crate, and `zerocopy` must be a direct dependency either way. Injecting them
would make that requirement invisible and its absence inscrutable.
- **It does not check for padding.** `zerocopy`'s `IntoBytes` derive already
rejects a padded type and reports the exact number of wasted bytes, which is
a better diagnostic than anything this macro could add.
Full documentation, including the wire format a payload is written in, lives
with the parent crate: <https://docs.rs/sensor-db>.
## License
Dual-licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.