ckb_fixed_hash/lib.rs
1//! Provide several simple fixed-sized hash data type and their static constructors.
2//!
3//! # Example
4//!
5//! ```rust
6//! use ckb_fixed_hash::{H256, h256};
7//!
8//! const N1: H256 = h256!("0xffffffff_ffffffff_ffffffff_fffffffe_baaedce6_af48a03b_bfd25e8c_d0364141");
9//! const N2: H256 = H256([
10//! 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
11//! 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36,
12//! 0x41, 0x41
13//! ]);
14//! assert_eq!(N1, N2);
15//!
16//! const ONE1: H256 = h256!("0x1");
17//! const ONE2: H256 = H256([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
18//! assert_eq!(ONE1, ONE2);
19//! ```
20
21pub use ckb_fixed_hash_core::{error, H160, H256, H512, H520};
22
23#[doc(hidden)]
24pub use ckb_fixed_hash_macros as internal;
25
26/// A macro used to create a const [`H160`] from a hexadecimal string or a trimmed hexadecimal
27/// string.
28#[macro_export]
29macro_rules! h160 {
30 ($arg:literal) => {{
31 use $crate::H160;
32 $crate::internal::h160!($arg)
33 }};
34}
35
36/// A macro used to create a const [`H256`] from a hexadecimal string or a trimmed hexadecimal
37/// string.
38#[macro_export]
39macro_rules! h256 {
40 ($arg:literal) => {{
41 use $crate::H256;
42 $crate::internal::h256!($arg)
43 }};
44}
45
46/// A macro used to create a const [`H512`] from a hexadecimal string or a trimmed hexadecimal
47/// string.
48#[macro_export]
49macro_rules! h512 {
50 ($arg:literal) => {{
51 use $crate::H512;
52 $crate::internal::h512!($arg)
53 }};
54}
55
56/// A macro used to create a const [`H520`] from a hexadecimal string or a trimmed hexadecimal
57/// string.
58#[macro_export]
59macro_rules! h520 {
60 ($arg:literal) => {{
61 use $crate::H520;
62 $crate::internal::h520!($arg)
63 }};
64}