Function string_to_bytes

Source
pub fn string_to_bytes(mystring: &str) -> Result<Vec<u8>, TypeError>
Expand description

Attempts to convert a hexadecimal string (optionally prefixed with “0x”) into a byte vector.

§Examples

use neo3::neo_types::string_to_bytes;
let hex_string = "0xdeadbeef";
let bytes = string_to_bytes(hex_string).unwrap();
assert_eq!(bytes, vec![0xde, 0xad, 0xbe, 0xef]);

let invalid_hex = "deadbeefg";
assert!(string_to_bytes(invalid_hex).is_err());