1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Serde functions for (de)serializing using FromStr and Display
//!
//! Useful for example in encoding SSZ `uintN` primitives using the "canonical JSON mapping"
//! described in the consensus-specs here: <https://github.com/ethereum/consensus-specs/blob/dev/ssz/simple-serialize.md#json-mapping>
//!
//! # Example
//! ```
//! use alloy_serde;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
//! pub struct Container {
//! #[serde(with = "alloy_serde::displayfromstr")]
//! value: u64,
//! }
//!
//! let val = Container { value: 18112749083033600 };
//! let s = serde_json::to_string(&val).unwrap();
//! assert_eq!(s, "{\"value\":\"18112749083033600\"}");
//!
//! let deserialized: Container = serde_json::from_str(&s).unwrap();
//! assert_eq!(val, deserialized);
//! ```
use crateString;
use ;
use ;
/// Serialize a type `T` that implements [fmt::Display] as a quoted string.
/// Deserialize a quoted string to a type `T` using [FromStr].