alloy_serde/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
4    html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
5)]
6#![cfg_attr(not(test), warn(unused_crate_dependencies))]
7#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
8#![cfg_attr(not(feature = "std"), no_std)]
9
10extern crate alloc;
11
12use alloc::format;
13use alloy_primitives::{hex, B256};
14use serde::Serializer;
15
16pub mod displayfromstr;
17
18mod optional;
19pub use self::optional::*;
20
21pub mod quantity;
22
23/// Storage related helpers.
24pub mod storage;
25pub use storage::JsonStorageKey;
26
27pub mod ttd;
28pub use ttd::*;
29
30mod other;
31pub use other::{OtherFields, WithOtherFields};
32
33/// Serialize a byte vec as a hex string _without_ the "0x" prefix.
34///
35/// This behaves the same as [`hex::encode`].
36pub fn serialize_hex_string_no_prefix<S, T>(x: T, s: S) -> Result<S::Ok, S::Error>
37where
38    S: Serializer,
39    T: AsRef<[u8]>,
40{
41    s.serialize_str(&hex::encode(x.as_ref()))
42}
43
44/// Serialize a [B256] as a hex string _without_ the "0x" prefix.
45pub fn serialize_b256_hex_string_no_prefix<S>(x: &B256, s: S) -> Result<S::Ok, S::Error>
46where
47    S: Serializer,
48{
49    s.serialize_str(&format!("{x:x}"))
50}