#hex-string #string #hex

hex_str

A library that helps handle hexadecimal strings

4 releases (2 breaking)

0.3.0 Oct 20, 2024
0.2.0 Aug 29, 2024
0.1.1 May 16, 2024
0.1.0 May 16, 2024

#147 in Value formatting

Download history 15192/week @ 2025-06-05 14191/week @ 2025-06-12 15741/week @ 2025-06-19 13645/week @ 2025-06-26 13576/week @ 2025-07-03 18102/week @ 2025-07-10 15521/week @ 2025-07-17 20126/week @ 2025-07-24 16258/week @ 2025-07-31 16524/week @ 2025-08-07 18573/week @ 2025-08-14 16549/week @ 2025-08-21 18488/week @ 2025-08-28 18783/week @ 2025-09-04 17387/week @ 2025-09-11 12460/week @ 2025-09-18

70,423 downloads per month

Apache-2.0 OR MIT

43KB
839 lines

hex_str

Handle and parse hex strings of constant and variable lengths

Example:

Example hex string, an md5 of an empty file:

d41d8cd98f00b204e9800998ecf8427e
use hex_str::HexString;

let s = "d41d8cd98f00b204e9800998ecf8427e";

// constant length, encoded in the type system
let u = HexStringN::<16>::try_parse(s).unwrap();
assert_eq!(u, "d41d8cd98f00b204e9800998ecf8427e");

// variable length
let v = HexString::try_parse(s).unwrap();
assert_eq!(v, "d41d8cd98f00b204e9800998ecf8427e");

Feature flags:

  • serde - adds the ability to serialize, and deserialize HexString's, and HexStringN's using serde.
  • rand - adds implementation of rand's Standard distribution, which enables random generation of HexStringN's directly.

Using serde feature:

use hex_str::HexString;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct Example {
    md5: HexString<16>,
}

let s = r#"
    {
        "md5": "d41d8cd98f00b204e9800998ecf8427e"
    }
"#;

let example: Example = serde_json::from_str(s).unwrap();
assert_eq!(example.md5, "d41d8cd98f00b204e9800998ecf8427e");

serde_json::to_string(&example).unwrap();

Using rand feature:

use hex_str::HexString;

let _: HexString<16> = rand::random();

Dependencies

~170–710KB
~16K SLoC