Alternative definition of string.hexToByteArray(N)

This definition is more robust. The previously existing version was
producing compilation errors in certain generic contexts. static
"regular" params are recommended in general as they are more flexible
than the explicit generic parameters.
This commit is contained in:
Zahary Karadjov 2021-03-19 03:56:01 +02:00
parent 6bcb21184a
commit ee78822e05
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 5 additions and 0 deletions

View File

@ -63,6 +63,11 @@ func hexToByteArray*[N: static[int]](hexStr: string): array[N, byte]
## Read an hex string and store it in a byte array. No "endianness" reordering is done.
hexToByteArray(hexStr, result)
func hexToByteArray*(hexStr: string, N: static int): array[N, byte]
{.raises: [ValueError, Defect], noInit, inline.}=
## Read an hex string and store it in a byte array. No "endianness" reordering is done.
hexToByteArray(hexStr, result)
func fromHex*[N](A: type array[N, byte], hexStr: string): A
{.raises: [ValueError, Defect], noInit, inline.}=
## Read an hex string and store it in a byte array. No "endianness" reordering is done.