Function in bytes coil-stdlib

from_hex

fn from_hex(string s) -> Result<Vec<byte>, string>
Import
use bytes::{from_hex};
Source: src/bytes.hy

Decodes hexadecimal text (either case) into bytes.

Parameters#

NameType
sstring

Returns#

Result<Vec<byte>, string>

Errors#

Returns Err when s has an odd length or a character that is not a hex digit.

Examples#

use bytes::{from_hex};
use tests::assert;
let b = from_hex("00AbfF") ?? Vec::new();
assert!(b.len() == 3 && b[1] == 171 as byte);
assert!(from_hex("abc").is_err());

See also#

  • region_eq: True when a[ao..ao+n) equals b[bo..bo+n) (caller guarantees bounds).
  • to_hex: Encodes buf as lowercase hexadecimal, two digits per byte.
  • slice: Returns a copy of src[start..end] (end exclusive), with both offsets clamped to the buffer.
  • concat: Returns a new buffer holding a followed by b.
  • eq: Returns true when a and b have the same length and the same bytes.
  • find_from: Returns the offset of the first needle in hay at or after start, or -1.
  • find: Returns the offset of the first needle in hay, or -1.
  • rfind: Returns the offset of the last needle in hay, or -1.
↑ ↓ navigate ↵ open