Expand description
The serde-hex crate contains various utilities for Serialization/Deserialization
of hexadecimal values using serde.
The core utility of this crate is the SerHex trait. Once implemented, SerHex
allows for easy configuration of hexadecimal serialization/deserialization with
serde-derive:
use stremio_serde_hex::{SerHex, StrictPfx};
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
struct Foo {
#[serde(with = "SerHex::<StrictPfx>")]
bar: [u8; 32]
}
The above example will cause serde to serialize Bar into a hexadecimal string
with strict sizing (padded with leading zeroes), and prefixing (leading 0x).
The possible configurations allow for any combination of strict/compact
representations, prefixing, and capitalizing (e.g.; Compact,
StrictCapPfx, etc…).
This crate provides implementations of SerHex for all unsigned integer types,
as well as generic impls for arrays of types which implement SerHex. The generic
impls apply only to strict variants of the trait, and only for arrays of length 1
through 64 (no impl is provided for arrays of length 0 since there isn’t really
a reasonable way to represent a zero-sized value in hex).
Modules§
- config
SerHexconfiguration variants.- macros
- Collection of useful macros.
- types
- Miscellaneous type used by this crate.
- utils
- various helper functions.
Macros§
- impl_
serhex_ bytearray - macro for implementing
SerHexfor a type which implementsFrom<[u8;n]>andAsRef<[u8]>. - impl_
serhex_ seq - implement
SerHexSeqfor a specified type.
Structs§
- Compact
- Config indicating compact representation with no capitalization and no prefixing.
- Compact
Cap - Config indicating compact representation with capitalization but no prefixing.
- Compact
CapPfx - Config indicating compact representation with capitalization and prefixing.
- Compact
Pfx - Config indicating compact representation with prefixing but no capitalization.
- Strict
- Config indicating a strict representation with no capiltaization and no prefixing.
- Strict
Cap - Config indicating a strict representation with capitalization but no prefixing.
- Strict
CapPfx - Config indicating a strict representation with capitalization and prefixing.
- Strict
Pfx - Config indicating a strict representation with prefixing but no capitalization.
Enums§
- Error
- top-level error kind of this crate
- Parse
HexError - error raised during hexadecimal parsing operations
Traits§
- HexConf
- Trait for supplying configuration to
SerHex. This trait takes noselfparameters, as it is intended to be applied unit structs. All default implementation are set tofalse. - SerHex
- Trait specifying custom serialization and deserialization logic from a
hexadecimal string to some arbitrary type. This trait can be used to apply
custom parsing when using serde’s
#[derive(Serialize,Deserialize)]flag. Just add#[serde(with = "SerHex")]above any fields which implement this trait. Simplistic default implimentations for the theserializeanddeserializemethods are provided based oninto_hex_rawandfrom_hex_rawrespectively. - SerHex
Opt - Variant of
SerHexfor serializing/deserializingOptiontypes. - SerHex
Seq - Variant of
SerHexfor serializing/deserializing sequence types as contiguous hexadecimal strings.