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] - type
AsRef<[u8]> -> SmallVec<[u8; 64]> - 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
[u8; N] -> String - type
&[u8; N] -> String - type
&[u8] -> String - type
Vec<u8> -> String - type
&Vec<u8> -> String
- type
slice prefixed functions
- Build fixed length
ArrayfromSlice- type
&[T] -> [T; N] - type
&[T] -> &[T; N]
- type
- Transform
SlicetoG- 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
HexBytesto 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]> -> SmallVec<[u8; 64]>
- 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
ArrayfromVec- type
Vec<T> -> [T; N]
- type
- Transform
VectoG- 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
bytes2hex time:
encode time:
hex_string time:
hex_encode_fallback
time:
encode time:
to_hex time:
hex2bytes time:
hex2bytes_unchecked
time:
hex2slice time:
hex2slice_unchecked
time:
decode time:
hex_decode time:
hex_decode_unchecked
time:
hex_decode_fallback
time:
decode time:
decode_to_slice time:
License
Licensed under either of Apache-2.0 or GPL-3.0 at your option.