#serialization #no-std

no-std serde_fmt

Write any serde::Serialize using the standard formatting APIs

5 releases (2 stable)

1.0.1 May 22, 2020
1.0.0 May 14, 2020
0.1.0 Feb 3, 2020
0.0.1 Jul 11, 2019
0.0.0 Jul 10, 2019

#118 in #serialization

Download history 268/week @ 2021-01-21 38/week @ 2021-01-28 41/week @ 2021-02-04 77/week @ 2021-02-11 76/week @ 2021-02-18 58/week @ 2021-02-25 73/week @ 2021-03-04 65/week @ 2021-03-11 93/week @ 2021-03-18 79/week @ 2021-03-25 99/week @ 2021-04-01 54/week @ 2021-04-08 55/week @ 2021-04-15 58/week @ 2021-04-22 115/week @ 2021-04-29 179/week @ 2021-05-06

412 downloads per month
Used in value-bag

Apache-2.0 OR MIT

17KB
462 lines

serde_fmt

Build Status 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.1"

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

[dependencies.serde_fmt]
version = "1.0.1"
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.1"

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.1"
features = ["std"]

Formatting a Serialize

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

# use serde::Serialize;
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

~150–265KB