rust-embedded-community/serde-json-core

Feature Request: Support defmt Formatting

avlec opened this issue · 3 comments

avlec commented

Working on a an embedded project where there is the ability to log errors and structures with defmt, this does require adding a new conditional dependency and adding a conditional derive as follows. This would be particularly useful for reporting errors from JSON de-serialization.

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
...
}

I would be happy to review such a PR, and have for a few other crates, but I have used defmt yet personally (my projects all predate it), so I'm not one that can test the implementation

avlec commented

I did a quick little test locally and just adding it how I did with the error from JSON de-serialization helped me understand that the decoder yielded this error TrailingCharacters which quickly led me to understand I needed to properly size my slice to from_slice. Would there be anywhere else these messages might be useful?

In general, the most useful approach I have seen is adding defmt::Format to the Error types, so for this library, it would be serde_json_core::ser::Error and serde_json_core::de::Error