serde_dbgfmt

Crates.ioserde_dbgfmt
lib.rsserde_dbgfmt
version0.1.0
sourcesrc
created_at2024-02-02 08:04:38.209334
updated_at2024-02-02 08:04:38.209334
descriptionDeserialize #[derive(Debug)] output using serde
homepage
repositoryhttps://github.com/phantomical/serde_dbgfmt
max_upload_size
id1124128
size67,559
Sean Lynch (Phantomical)

documentation

README

serde_dbgfmt

ci

Deserialize the output of #[derive(Debug)] using serde.

This library allows you to deserialize the debug representation of rust types via serde. This includes all types which use #[derive(Debug)] but also any other ones that use the debug helpers in std::fmt to output their debug representation.

Example

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Test {
    message: String,
}

let text = format!("{:?}", Test { message: "Hello, World!".into() });
let value: Test = serde_defmt::from_str(&text)
    .expect("failed to deserialize from the debug repr");

assert_eq!(value.message, "Hello, World!");

Caveats

  • This library parses the format emitted by the debug helpers in std::fmt. This should cover all types with #[derive(Debug)] and many custom impls but since custom impls can do anything it is not guaranteed to work.
  • The debug format emitted by the debug helpers is not guaranteed to be stable. While it has remained rather stable in the past there is no guarantee that it will not be changed in the future.
  • The names of structs used to deserialize must match those in the text debug representation. You can use #[serde(rename = "..")] if you want to use a different struct name in your codebase.

See Also

  • The serde_fmt library is the inverse of this crate. It allows you to print a debug representation for any struct which implements [Serialize].
Commit count: 0

cargo fmt