#serialization #debugging #write #no-std #formatting #standard #convert

no-std serde_fmt

Write any serde::Serialize using the standard formatting APIs

7 releases (4 stable)

1.0.3 May 5, 2023
1.0.2 Apr 8, 2023
1.0.1 May 22, 2020
0.1.0 Feb 3, 2020
0.0.1 Jul 11, 2019

#698 in Encoding

Download history 64229/week @ 2023-12-15 25803/week @ 2023-12-22 43752/week @ 2023-12-29 70777/week @ 2024-01-05 76892/week @ 2024-01-12 81329/week @ 2024-01-19 72064/week @ 2024-01-26 75504/week @ 2024-02-02 73646/week @ 2024-02-09 84351/week @ 2024-02-16 96801/week @ 2024-02-23 92808/week @ 2024-03-01 80405/week @ 2024-03-08 86956/week @ 2024-03-15 90870/week @ 2024-03-22 83955/week @ 2024-03-29

357,300 downloads per month
Used in 2 crates (via value-bag-serde1)

Apache-2.0 OR MIT

19KB
476 lines

serde_fmt

rust Latest version Documentation Latest

Convert any serde::Serialize into a std::fmt::Debug:

fn takes_serialize(v: impl Serialize) {
    dbg!(serde_fmt::to_debug(&v));

    // Do something with `v`
}

Supported rustc

This library requires a Rust compiler that's at least 1.42.0.

Getting started

Add serde_fmt to your Cargo.toml:

[dependencies.serde_fmt]
version = "1.0.3"

By default, this library will depend on the standard library. To use it in no-std environments, you can disable the default crate features:

[dependencies.serde_fmt]
version = "1.0.3"
default-features = false

lib.rs:

serde -> std::fmt

This library lets you take any Serialize and format it as if it's Debug. The format produced is the same as if the type derived Debug, and any formatting flags will be preserved.

Getting started

Add serde_fmt to your Cargo.toml:

[dependencies.serde_fmt]
version = "1.0.3"

By default, this library doesn't depend on the standard library. You can enable support with the std Cargo feature:

[dependencies.serde_fmt]
version = "1.0.3"
features = ["std"]

Formatting a Serialize

Use the to_debug function to treat a serde::Serialize like a std::fmt::Debug:

fn takes_serialize(v: impl Serialize) {
// You can dump any `Serialize` using the
// standard `dbg!` macro
dbg!(serde_fmt::to_debug(&v));

// do something with `v`
}

Dependencies

~110–360KB