Crate serde_dbgfmt

Crate serde_dbgfmt 

Source
Expand description

This library lets you deserialize the output of Debug into a serde struct.

If you would like to do the opposite (output Debug via Serialize) take a look at serde_fmt.

§Getting Started

Add serde_dbgfmt to your Cargo.toml:

[dependencies]
serde_dbgfmt = "0.1.1"

§Deserializing a struct

use serde::Deserialize;

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

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

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

§Caveats and Limitations

  • This library parses the format emitted by the debug helpers in std::fmt. Custom debug representations will not necessarily use these debug helpers and may not emit output that is compatible with them.
  • The debug format emitted by the helpers above is not guaranteed to be stable. While it has remained remarkably stable there is no guarantee that it will not be changed in the future.
  • The names of the 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.

Structs§

Deserializer
A serde deserializer for rust’s debug format.
Error

Functions§

from_dbg
Parse the debug representation of U as a T.
from_str
Parse a T from the string containing its debug representation.