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))]
8#![cfg_attr(not(feature = "std"), no_std)]
9
10extern crate alloc;
11
12use alloy_primitives::{hex, B256};
13use serde::Serializer;
14
15pub mod displayfromstr;
16
17mod optional;
18pub use self::optional::*;
19
20pub mod quantity;
21
22/// Storage related helpers.
23pub mod storage;
24pub use storage::JsonStorageKey;
25
26pub mod ttd;
27pub use ttd::*;
28
29mod other;
30pub use other::{OtherFields, WithOtherFields};
31
32/// Serialize a byte vec as a hex string _without_ the "0x" prefix.
33///
34/// This behaves the same as [`hex::encode`].
35pub fn serialize_hex_string_no_prefix<S, T>(x: T, s: S) -> Result<S::Ok, S::Error>
36where
37    S: Serializer,
38    T: AsRef<[u8]>,
39{
40    s.serialize_str(&hex::encode(x.as_ref()))
41}
42
43/// Serialize a [B256] as a hex string _without_ the "0x" prefix.
44pub fn serialize_b256_hex_string_no_prefix<S>(x: &B256, s: S) -> Result<S::Ok, S::Error>
45where
46    S: Serializer,
47{
48    s.collect_str(&format_args!("{x:x}"))
49}