pub fn decode_array<const N: usize>(hex: &str) -> Result<[u8; N], HexError> {
    let mut bytes = [0u8; N];
    if hex.len() % 2 != 0 {
        return Err(HexError::InvalidHex);
    }
    if hex.len() != N * 2 {
        return Err(HexError::InvalidLength);
    }
    for (hex_byte, byte) in hex.as_bytes().chunks(2).zip(bytes.iter_mut()) {
        *byte = hex_val(hex_byte[0])? << 4 | hex_val(hex_byte[1])?
    }
    Ok(bytes)
}
/// Decode some hex bytes into a fixed length array.
///
/// # Examples
/// ```
/// use secp256kfun::{G, hex};
/// let G_bytes : [u8;33] = hex::decode_array("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798").unwrap();
/// assert_eq!(G_bytes, G.to_bytes());
Decode some hex bytes into a fixed length array.
Decode some hex bytes into a fixed length array .
pub fn decode_array<const N: usize>(hex: &str) -> Result<[u8; N], HexError> {
    let mut bytes = [0u8; N];
    if hex.len() % 2 != 0 {
        return Err(HexError::InvalidHex);
    }
    if hex.len() != N * 2 {
        return Err(HexError::InvalidLength);
    }
    for (hex_byte, byte) in hex.as_bytes().chunks(2).zip(bytes.iter_mut()) {
        *byte = hex_val(hex_byte[0])? << 4 | hex_val(hex_byte[1])?
    }
    Ok(bytes)
}
pub fn decode_array < const N : usize > ( hex : & str ) -> Result < [ u8 ; N ] , HexError > { let mut bytes = [ 0u8 ; N ] ; if hex . len ( ) % 2 != 0 { return Err ( HexError :: InvalidHex ) ; } if hex . len ( ) != N * 2 { return Err ( HexError :: InvalidLength ) ; } for ( hex_byte , byte ) in hex . as_bytes ( ) . chunks ( 2 ) . zip ( bytes . iter_mut ( ) ) { * byte = hex_val ( hex_byte [ 0 ] ) ? << 4 | hex_val ( hex_byte [ 1 ] ) ? } Ok ( bytes ) }
Decode some hex bytes into a fixed length array.
Decode some hex bytes into a fixed length array .
hex
&str
hex
&str
examples
None