#hex-string #hex #string #str #hexstring

hex_str

A library that helps handle hexadecimal strings of specified length

3 unstable releases

0.2.0 Aug 29, 2024
0.1.1 May 16, 2024
0.1.0 May 16, 2024

#48 in Value formatting

Download history 16/week @ 2024-05-28 12/week @ 2024-06-04 11/week @ 2024-06-11 10/week @ 2024-06-18 21/week @ 2024-06-25 871/week @ 2024-07-02 3630/week @ 2024-07-09 5209/week @ 2024-07-16 9920/week @ 2024-07-23 28238/week @ 2024-07-30 42771/week @ 2024-08-06 38855/week @ 2024-08-13 53318/week @ 2024-08-20 51156/week @ 2024-08-27 39469/week @ 2024-09-03 34783/week @ 2024-09-10

183,680 downloads per month

Apache-2.0 OR MIT

30KB
533 lines

hex_str

Example hex string, an md5 of an empty file:

d41d8cd98f00b204e9800998ecf8427e

Example:

use hex_str::HexString;

let s = "d41d8cd98f00b204e9800998ecf8427e";
let v = HexString::<16>::try_parse(s).unwrap();

assert_eq!(v, "d41d8cd98f00b204e9800998ecf8427e");

Feature flags:

  • serde - adds the ability to serialize and deserialize a HexString using serde.
  • rand - adds implementation of rand's Standard distribution, which enables random generation of HexString'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

~0.3–0.8MB
~19K SLoC