hex-serde-util

This crate provides a convenient approach to serializing/deserializing hex numbers with hex string of several formats.

Examples

```rust use hexserdeutil::{HexUsizeUpper, HexUsizeLower, HexUsizePrefixUpper, HexUsizePrefixLower};

let lowerdata: HexUsizeLower = 0x1ausize.into(); let upperdata: HexUsizeUpper = 0x1ausize.into(); let prefixlowerdata: HexUsizePrefixLower = 0x1ausize.into(); let prefixupperdata: HexUsizePrefixUpper = 0x1ausize.into(); asserteq!(&serdejson::tostring(&lowerdata).unwrap(), r#""1a""#); asserteq!(&serdejson::tostring(&upperdata).unwrap(), r#""1A""#); asserteq!( &serdejson::tostring(&prefixlowerdata).unwrap(), r#""0x1a""# ); asserteq!( &serdejson::tostring(&prefixupperdata).unwrap(), r#""0x1A""# ); asserteq!( serdejson::fromstr::(r#""1a""#).unwrap(), 0x1ausize.into() ); asserteq!( serdejson::fromstr::(r#""1A""#).unwrap(), 0x1ausize.into() ); asserteq!( serdejson::fromstr::(r#""0x1a""#).unwrap(), 0x1ausize.into() ); asserteq!( serdejson::fromstr::(r#""0x1A""#).unwrap(), 0x1ausize.into() ); ```

In summary, this crate provides a way to serialize/deserialize hex number from/to hex string with:

Generally, a project may only use one format of hex string, so just use an alias when using this crate in your project for convenience:

```rust use hexserdeutil::HexUsizePrefixUpper as Hex; use serde::Deserialize;

[derive(Deserialize)]

struct AnalysisInfo { base_addr: Hex, } ```

Necessity

serde provides many attributes for customizing serialization/deserialization, such as

These attributes can be used to work with hex strings, but there are some disadvantages:

This crate handles these problems.

Usages

Just as shown above, users can just use types provided by this crate when serialize/deserialize hex strings with hex numbers. Moreover, these types also implements some convenient traits: