Commit 68a9640
authored
refactor!: split into Tmp108 (blocking) and AsyncTmp108 (async) (0.7.0) (#48)
## Summary
Architectural refactor — the single `maybe-async-cfg`-generated
`Tmp108<I2C>` becomes two named driver types: **`Tmp108`** (blocking,
`embedded-hal`) and **`AsyncTmp108`** (async, `embedded-hal-async`).
Both are available simultaneously when both relevant features are
enabled. Shared register-codec logic lives in a private `mod ops` of
pure functions. The `maybe-async-cfg` dependency is dropped entirely.
This is the architectural sequel to #47 — recommended by the
`@architect` review at the same time as the reliability fixes, and
deliberately deferred to a follow-up so each PR could be reviewed and
hardware-verified independently.
Design spec at
[`docs/superpowers/specs/2026-06-04-tmp108-type-split-design.md`](https://github.com/felipebalbi/tmp108/blob/named-types/docs/superpowers/specs/2026-06-04-tmp108-type-split-design.md).
## What changes (per commit)
| Commit | Scope | Breaking? |
|---|---|---|
| `docs: add design spec for type-split refactor (0.7.0)` | spec only |
no |
| `refactor: extract pure register codec to private mod ops` | new `mod
ops` with `to_celsius` / `to_raw` / `snap_hysteresis` / `decode_config`
/ `apply_config` / constants. Method bodies become thin shells. | no |
| `refactor!: split into Tmp108 (blocking) and AsyncTmp108 (async)` |
the big mechanical step — drops `maybe-async-cfg`, splits the struct +
every impl, splits `Interface` into `Interface` + `AsyncInterface`,
kills the `# fn main()` doctest shim (AGENTS.md Gotcha 3), and adds
first-class doctests on the async type. `embedded-sensors-hal-async` now
implies `async` in `Cargo.toml`. | **yes** |
| `feat!: make AlertTmp108::tmp108 private; add
sensor/sensor_mut/into_inner` | hide the inner field; `sensor()` /
`sensor_mut()` for access; `into_inner() -> (AsyncTmp108<I2C>, ALERT)`
as the inverse of `into_alert` | **yes** |
| `feat: add Eq to Config; add Clone/Copy/PartialEq/Eq to Error<E, P>` |
architect's bonus point #3/#4 — derive on `Config`, conditional manual
impls on `Error<E, P>` | no |
| `docs(AGENTS): update for type-split architecture` | replace Gotcha 3
(maybe-async-cfg), update Gotchas 4/5 to mention `AsyncTmp108`, rewrite
"Where to put new things", note matrix shrinkage | no |
| `docs(README): update snippets and Cargo features for AsyncTmp108` |
snippets switched to `AsyncTmp108` / `sensor_mut()`; features table
updated; cancel-safety gotcha surfaced in the README too | no |
| `chore: bump version to 0.7.0 and update CHANGELOG` | release |
release |
## Why two named types
The maintainer-facing complaint and the user-facing complaint about
`maybe-async-cfg` are the same: the macro promises a "single source"
that it doesn't actually deliver — every method body in 0.6.0
contained hand-written `#[cfg(feature = "async")]` arms duplicating
the meaningful work, the trait impls (`embedded-sensors-hal*`,
`AlertTmp108`) were hand-written twice already, and the test module
had parallel `blocking` / `asynchronous` submodules. The macro
*added* the doctest workaround (Gotcha 3, the `# fn main()` shim)
*and* prevented async paths from getting any doctest coverage at all
— for negative payoff.
This PR captures the architect's verdict: do the duplication
honestly at the struct level, share the *actual* shared logic
(register encoding/decoding, hysteresis snapping, range validation)
in a `mod ops`, and let each driver carry its own doctest in the
right shape.
Quantified wins:
- Doctest count with `--all-features`: 18 → **47** (2.6×; async
paths now covered for the first time).
- `cargo hack --feature-powerset` matrix: 8 → **6** combinations
(`embedded-sensors-hal-async` now implies `async`, the two
previously-dead-code combos are gone).
- `cargo vet --locked`: 177 → **170** audited (the `maybe-async-cfg`
proc-macro subtree is dropped).
- AGENTS.md gotchas: 10 → 10, but Gotcha 3 (the `# fn main()` shim
that bit every new contributor) is replaced with a description of
the parallel-types-share-`ops` architecture.
- `src/lib.rs`: ~1700 → ~2850 lines. The increase is the doubled
shells + doubled doctests; the meaningful work shrinks (it's in
`mod ops` now).
## Migration (also in CHANGELOG)
For most downstream code there is exactly one mechanical change:
```rust
// Before
use tmp108::Tmp108;
let mut tmp = Tmp108::new_with_a0_gnd(i2c);
let t = tmp.temperature().await?;
// After
use tmp108::AsyncTmp108;
let mut tmp = AsyncTmp108::new_with_a0_gnd(i2c);
let t = tmp.temperature().await?;
```
Blocking users keep `use tmp108::Tmp108` unchanged.
Downstream code reaching into `AlertTmp108::tmp108` (the formerly
public field) should switch to `tmp.sensor()` / `tmp.sensor_mut()`
or use `into_inner()` to destructure. The `AlertTmp108` `Self::Error`
is now `Error<I2C::Error, ALERT::Error>` (was `Error<I2C::Error>`);
code that named the type explicitly needs the second parameter.
`embedded-sensors-hal-async` now implies `async`, so feature
specifications that listed both are unaffected; those who only
listed the trait feature were silently building dead code and will
now get the right behavior automatically.
## Test coverage
The mock `Transaction` expectations in the existing test suite are
**byte-for-byte identical** to PR #47's — proof that the wire
protocol is unchanged. New tests cover the new surface:
- `mod ops_tests` — 8 unit tests of the pure functions (to_celsius
including non-zero-low-bits, to_raw rejection + boundary,
snap_hysteresis acceptance/rejection, decode/apply round-trip, POR
constant pin, `Config: Eq` compile-check, `Error<E,P>` trait
derives).
- All `tests::asynchronous` mocks updated to `AsyncTmp108` (purely
type-renamed; expectations unchanged).
- 18 new async doctests on `AsyncTmp108` methods, plus 3 on
`AlertTmp108::sensor` / `sensor_mut` / `into_inner`.
## Local matrix verified
Against today's `upstream/main` (post-merge of #47):
- `cargo +nightly fmt --check`
- `cargo clippy --all-features --all-targets -- -W clippy::suspicious -W
clippy::correctness -W clippy::perf -W clippy::style`
- `cargo doc --no-deps --all-features --locked`
- `cargo test --locked` (24/18 unit/doctests) ; `-F async` (25/37) ;
`-F async,embedded-sensors-hal-async` (31/47)
- `cargo build --examples --locked` × 4 feature combos
- `cargo hack --feature-powerset check --locked` (6/6)
- `./scripts/check-readme-snippets.sh` (3/3)
- `cargo vet --locked` (170 audited)
`cargo-semver-checks` not installed locally; CI will flag the breaking
changes and confirm the 0.7.0 bump.
Hardware verification was **not** performed for this PR. The
register-level interactions are unchanged (proven by the unmodified
mock expectations) and `AlertTmp108`'s wire-level behavior is
untouched, but a hands-on pass on `oneshot` / `continuous` /
`sensor_trait` / `alert_interrupt` / `alert_comparator` against a
Pico de Gallo before merge would be valuable per AGENTS.md.
## Risks called out in the spec
1. **`Tmp108 → AsyncTmp108` rename has wide blast radius** for async
downstream code. The migration is mechanical, the CHANGELOG covers
it, and the new name (`AsyncTmp108`) follows the
`embedded-storage` / `embedded-storage-async` ecosystem convention.
2. **Big single commit for the type-split.** ~1100 lines of `src/lib.rs`
are rewritten in `refactor!: split into Tmp108 (blocking) and
AsyncTmp108 (async)`. Mitigation: shared logic was already
extracted into `mod ops` in the prior commit, the wire-level mock
expectations don't change (any test failure means a real bug), and
each shell pair is small (~5 lines) and parallel — review can scan
them as pairs.
3. **`embedded-sensors-hal-async` now requires `async`.** This is a
*strengthening* of an existing implicit requirement (the old combo
built dead code). CHANGELOG calls it out.
4. **Binary-breaking `Error` generic parameter** was added in PR #47;
this PR only adds derives. No additional semver impact beyond the
type renames called out above.
## Out of scope
- Hardware verification of TLow/THigh resolution (H3 from #47's
review) — still hardware-only.
- Diagnostic counters / sticky flags (L5).
- Probe-on-construct (`new() -> Result<...>`) — rejected in #47's
review and not revisited.
- Any new public methods beyond `AlertTmp108::sensor` /
`sensor_mut` / `into_inner`.
## Conventional Commits compliance
Every commit follows
[Conventional Commits
v1.0.0](https://www.conventionalcommits.org/en/v1.0.0/).
Breaking commits have `!` after the type and a `BREAKING CHANGE:`
footer. Every commit ends with an
`Assisted-by: opencode:claude-opus-4.7-1m-internal` trailer per
AGENTS.md.
Follows #47.1 parent aad2141 commit 68a9640
13 files changed
Lines changed: 1861 additions & 680 deletions
File tree
- docs/superpowers/specs
- examples
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
32 | 41 | | |
33 | 42 | | |
34 | 43 | | |
| |||
42 | 51 | | |
43 | 52 | | |
44 | 53 | | |
45 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
46 | 62 | | |
47 | 63 | | |
48 | 64 | | |
| |||
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
| 72 | + | |
56 | 73 | | |
57 | | - | |
| 74 | + | |
| 75 | + | |
58 | 76 | | |
59 | 77 | | |
60 | | - | |
61 | | - | |
| 78 | + | |
| 79 | + | |
62 | 80 | | |
63 | 81 | | |
64 | 82 | | |
65 | 83 | | |
66 | | - | |
| 84 | + | |
67 | 85 | | |
68 | 86 | | |
69 | 87 | | |
| |||
80 | 98 | | |
81 | 99 | | |
82 | 100 | | |
83 | | - | |
84 | | - | |
85 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
86 | 104 | | |
87 | 105 | | |
88 | 106 | | |
| 107 | + | |
| 108 | + | |
89 | 109 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
93 | 114 | | |
94 | 115 | | |
95 | | - | |
| 116 | + | |
| 117 | + | |
96 | 118 | | |
97 | 119 | | |
98 | 120 | | |
| |||
181 | 203 | | |
182 | 204 | | |
183 | 205 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
222 | 231 | | |
223 | 232 | | |
224 | 233 | | |
| |||
234 | 243 | | |
235 | 244 | | |
236 | 245 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
242 | 251 | | |
243 | 252 | | |
244 | 253 | | |
| |||
405 | 414 | | |
406 | 415 | | |
407 | 416 | | |
408 | | - | |
| 417 | + | |
| 418 | + | |
409 | 419 | | |
410 | 420 | | |
411 | 421 | | |
412 | | - | |
| 422 | + | |
413 | 423 | | |
414 | 424 | | |
415 | 425 | | |
416 | 426 | | |
417 | 427 | | |
| 428 | + | |
418 | 429 | | |
419 | 430 | | |
420 | 431 | | |
421 | 432 | | |
422 | 433 | | |
423 | | - | |
| 434 | + | |
424 | 435 | | |
425 | 436 | | |
426 | 437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
7 | 75 | | |
8 | 76 | | |
9 | 77 | | |
| |||
0 commit comments