Crates.io | hex_str |
lib.rs | hex_str |
version | 0.3.0 |
source | src |
created_at | 2024-05-16 17:11:58.312026 |
updated_at | 2024-10-20 14:04:25.032267 |
description | A library that helps handle hexadecimal strings |
homepage | |
repository | https://github.com/vmdln/hex_str |
max_upload_size | |
id | 1242291 |
size | 54,451 |
hex_str
Handle and parse hex strings of constant and variable lengths
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");
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.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();
rand
feature:use hex_str::HexString;
let _: HexString<16> = rand::random();