sensor-db-derive 0.1.0

Derive macro for sensor-db's SensorData trait
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 26.0 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 43.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • EmilLindfors

sensor-db-derive

#[derive(SensorData)] for 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:

sensor-db = { version = "0.1", features = ["derive"] }
zerocopy  = { version = "0.8", features = ["derive"] }
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

at your option.