Repository navigation
feat(core): defmt::Format for every type the log macros format (#352, 1/3) - #358
Merged
Merged
Conversation
Groundwork for forwarding `log_*!` to defmt (#352): under core's `defmt` feature, every argument type core's log lines format now implements `defmt::Format`. - `TransportError`, `CodecError`, `AuthError`, `FrameFault`: derived. - `DbError`, `SerializeFailure`: through their `Display` impl (`defmt::Display2Format`). `DbError`'s `std`-only variants carry `io::Error` / `serde_json::Error`, which do not implement `Format`, and docs.rs builds with every feature on, so a derive would break that build. - core's `defmt` feature enables `defmt/alloc`, for `String`, `Vec<String>` and `Arc<str>`. - A compile-time assertion keeps all of them `Format` under `defmt`. Found by building every defmt-capable crate for thumbv7em with the macro branch in place. No behaviour change on its own. Part of #352. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PR 1 of 3 into
feat/352-log-defmtfor #352: the groundwork, so thatlog_*!can forward todefmtin PR 2.How the scope was found: I temporarily added the
defmtbranch to thelog_*!macros and built every crate that can build withdefmtforthumbv7em(core in four feature combinations, MQTT, KNX, serial, TCP). The compiler then listed every argument type withoutdefmt::Format. This PR covers core's share:TransportError,CodecError,AuthError,FrameFault#[cfg_attr(feature = "defmt", derive(defmt::Format))]DbErrorDisplay(defmt::Display2Format)SerializeFailure(pub(crate))DisplayString,Vec<String>,Arc<str>defmtfeature enablesdefmt/allocWhy
DbErrorisn't derived: itsstd-only variants carryio::Error/serde_json::Error, which don't implementFormat. The workspace builds docs.rs withall-features = true(Cargo.toml:186), sostdanddefmtare on together there and a derive would break that build.Display2Formatuses thethiserrortext, so thedefmtline matches thetracing/logline. It isn't interned, which is fine for error paths. This follows the existing hand-written impl forSerializeError(connector.rs).Guard: a compile-time assertion in
lib.rsrequiresFormatfor all of these types as soon asdefmt(withconnector-session) is on, so none can lose it before PR 2 uses them.No behaviour change: nothing calls these impls until PR 2.
Left for PR 2 (found by the same build): the
defmtbranch in the macros, the__privatere-export, and inaimdb-knx-connectora directdefmtdependency (defmt's macros expand to absolutedefmt::paths) plusdefmt/ip_in_core(forcore::net::SocketAddr). Also the three std-only crates (zenoh, sync, UDS) need to know the newdefmtfeature name, because ofunexpected_cfgsin#[macro_export]macros.Verified locally
aimdb-core.thumbv7emcheck/clippy command in the Makefile foraimdb-core,aimdb-mqtt-connector,aimdb-knx-connector,aimdb-serial-connectorandaimdb-tcp-connector.defmtonthumbv7em(alloc,connector-session,remote,defmt,alloc,defmt,alloc,observability,defmt).cargo check/cargo doc -D warningsforaimdb-core --all-features(stdanddefmttogether, as on docs.rs).Related Issue
🤖 Generated with Claude Code
https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e