1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Handle and parse hex strings of constant and variable lengths
//!
//! ## Example:
//! Example hex string, an md5 of an empty file:
//! ```text
//! d41d8cd98f00b204e9800998ecf8427e
//! ```
//! ```
//! use hex_str::{HexString, HexStringN};
//!
//! 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`](https://docs.rs/rand/0.8.4/rand/distributions/struct.Standard.html)
//! distribution, which enables random generation of [`HexStringN`]'s directly.
//!
//! #### Using `serde` feature:
//! ```
//! #[cfg(feature = "serde")]
//! {
//! use hex_str::HexStringN;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Deserialize, Serialize)]
//! struct Example {
//! md5: HexStringN<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:
//! ```
//! #[cfg(feature = "rand")]
//! {
//! use hex_str::HexStringN;
//!
//! let _: HexStringN<16> = rand::random();
//! }
//! ```
pub use ;
pub use HexString;
pub use HexStringN;