array-bytes
A Collection of Array/Bytes/Hex Utilities.
Abilities
TryFromHex
trait
- Convert hex to num
- type
AsRef<[u8]> -> isize
- type
AsRef<[u8]> -> i8
- type
AsRef<[u8]> -> i16
- type
AsRef<[u8]> -> i32
- type
AsRef<[u8]> -> i64
- type
AsRef<[u8]> -> i128
- type
AsRef<[u8]> -> usize
- type
AsRef<[u8]> -> u8
- type
AsRef<[u8]> -> u16
- type
AsRef<[u8]> -> u32
- type
AsRef<[u8]> -> u64
- type
AsRef<[u8]> -> u128
- type
- Convert hex to array
- type
AsRef<[u8]> -> [u8; N]
,N = { [1, 64], 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 }
- type
AsRef<[u8]> -> Vec<u8>
- type
Hex
trait
- Convert num to hex
- type
isize -> String
- type
i8 -> String
- type
i16 -> String
- type
i32 -> String
- type
i64 -> String
- type
i128 -> String
- type
usize -> String
- type
u8 -> String
- type
u16 -> String
- type
u32 -> String
- type
u64 -> String
- type
u128 -> String
- type
- Convert array to hex
- type
Vec<u8> -> String
- type
[u8; N] -> String
,N = { [1, 64], 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536 }
- type
&[u8] -> String
- type
slice
prefixed functions
- Build fixed length
Array
fromSlice
- type
&[T] -> [T; N]
- type
&[T] -> &[T; N]
- type
- Transform
Slice
toG
- type
&[T] -> G
- e.g.
&[0_u8, ...] -> [u8; 20] -> H160
- type
prefix
and suffix
functions
- Prefixes/suffixes the given element to the given slice to make it a fixed-size array of length
N
.
bytes
prefixed functions
- Convert bytes to hex
- type
AsRef<[u8]> -> String
- type
hex
prefixed functions
- Convert
HexBytes
to hex- type
&[u8] -> &str
- e.g.
b"0x..." -> "0x..."
- type
- Transform hex from
Array
- type
&str -> [u8; N]
- type
- Convert hex to bytes
- type
AsRef<[u8]> -> Vec<u8>
- type
- Convert hex to
Slice
- type
AsRef<[u8]> -> &[u8]
- type
- Transform hex to
T
- type
AsRef<[u8]> -> T
- e.g.
"0x..." -> [u8; 20] -> H160
- type
vec
prefixed functions
- Build fixed length
Array
fromVec
- type
Vec<T> -> [T; N]
- type
- Transform
Vec
toG
- type
Vec<T> -> G
- e.g.
vec![0_u8, ...] -> [u8; 20] -> H160
- type
Serde support (require feature serde
)
#[serde(deserialize_with = "array_bytes::hex_deserialize_n_into")]
- type
S -> T
- e.g.
"0x..." -> H160
- type
#[serde(deserialize_with = "array_bytes::de_try_from_hex")]
- type
S -> impl TryFromHex
- e.g.
"0xA" -> 10_u32
- type
#[serde(serialize_with = "array_bytes::ser_hex/array_bytes::ser_hex_without_prefix")]
- type
S -> impl Hex
- e.g.
"0x00" -> vec![0_u8]
- type
Benchmark results
:
Found 4 outliers among 100 measurements
2 low mild
1 high mild
1 high severe
encode time:
hex_string time:
hex_encode_fallback
time:
Found 1 outliers among 100 measurements
1 high mild
encode time:
Found 14 outliers among 100 measurements
1 low severe
4 low mild
6 high mild
3 high severe
to_hex time:
Found 16 outliers among 100 measurements
1 low mild
2 high mild
13 high severe
hex2bytes time:
Performance has regressed.
Found 11 outliers among 100 measurements
7 low mild
4 high mild
hex2bytes_unchecked
time:
hex2slice time:
Performance has regressed.
Found 12 outliers among 100 measurements
2 high mild
10 high severe
hex2slice_unchecked
time:
Performance has regressed.
decode time:
Performance has improved.
Found 2 outliers among 100 measurements
1 low mild
1 high severe
hex_decode time:
Performance has improved.
Found 1 outliers among 100 measurements
1 high mild
hex_decode_unchecked
time:
Found 3 outliers among 100 measurements
2 low severe
1 low mild
hex_decode_fallback
time:
Found 7 outliers among 100 measurements
2 low severe
4 low mild
1 high mild
decode time:
decode_to_slice time:
Found 13 outliers among 100 measurements
5 high mild
8 high severe
from_hex time:
bytes2hex time
License
Licensed under either of Apache-2.0 or GPL-3.0 at your option.