Trait reth::core::primitives::alloy_primitives::hex::FromHex

pub trait FromHex: Sized {
    type Error;

    // Required method
    fn from_hex<T>(hex: T) -> Result<Self, Self::Error>
       where T: AsRef<[u8]>;
}
Expand description

Types that can be decoded from a hex string.

This trait is implemented for Vec<u8> and small u8-arrays.

§Example

use const_hex::FromHex;

let buffer = <[u8; 12]>::from_hex("48656c6c6f20776f726c6421")?;
assert_eq!(buffer, *b"Hello world!");

Required Associated Types§

type Error

The associated error which can be returned from parsing.

Required Methods§

fn from_hex<T>(hex: T) -> Result<Self, Self::Error>
where T: AsRef<[u8]>,

Creates an instance of type Self from the given hex string, or fails with a custom error type.

Both, upper and lower case characters are valid and can even be mixed (e.g. f9b4ca, F9B4CA and f9B4Ca are all valid strings).

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl FromHex for Box<[i8]>

Available on crate feature alloc only.
§

type Error = FromHexError

§

fn from_hex<T>(hex: T) -> Result<Box<[i8]>, <Box<[i8]> as FromHex>::Error>
where T: AsRef<[u8]>,

§

impl FromHex for Box<[u8]>

Available on crate feature alloc only.
§

type Error = FromHexError

§

fn from_hex<T>(hex: T) -> Result<Box<[u8]>, <Box<[u8]> as FromHex>::Error>
where T: AsRef<[u8]>,

§

impl FromHex for Vec<i8>

Available on crate feature alloc only.
§

type Error = FromHexError

§

fn from_hex<T>(hex: T) -> Result<Vec<i8>, <Vec<i8> as FromHex>::Error>
where T: AsRef<[u8]>,

§

impl FromHex for Vec<u8>

Available on crate feature alloc only.
§

type Error = FromHexError

§

fn from_hex<T>(hex: T) -> Result<Vec<u8>, <Vec<u8> as FromHex>::Error>
where T: AsRef<[u8]>,

§

impl<T> FromHex for Cow<'_, T>
where T: ToOwned + ?Sized, <T as ToOwned>::Owned: FromHex,

Available on crate feature alloc only.
§

type Error = <<T as ToOwned>::Owned as FromHex>::Error

§

fn from_hex<U>(hex: U) -> Result<Cow<'_, T>, <Cow<'_, T> as FromHex>::Error>
where U: AsRef<[u8]>,

§

impl<T> FromHex for Box<T>
where T: FromHex,

Available on crate feature alloc only.
§

type Error = <T as FromHex>::Error

§

fn from_hex<U>(hex: U) -> Result<Box<T>, <Box<T> as FromHex>::Error>
where U: AsRef<[u8]>,

§

impl<T> FromHex for Rc<T>
where T: FromHex,

Available on crate feature alloc only.
§

type Error = <T as FromHex>::Error

§

fn from_hex<U>(hex: U) -> Result<Rc<T>, <Rc<T> as FromHex>::Error>
where U: AsRef<[u8]>,

§

impl<T> FromHex for Arc<T>
where T: FromHex,

Available on crate feature alloc only.
§

type Error = <T as FromHex>::Error

§

fn from_hex<U>(hex: U) -> Result<Arc<T>, <Arc<T> as FromHex>::Error>
where U: AsRef<[u8]>,

§

impl<const N: usize> FromHex for [i8; N]

§

type Error = FromHexError

§

fn from_hex<T>(hex: T) -> Result<[i8; N], <[i8; N] as FromHex>::Error>
where T: AsRef<[u8]>,

§

impl<const N: usize> FromHex for [u8; N]

§

type Error = FromHexError

§

fn from_hex<T>(hex: T) -> Result<[u8; N], <[u8; N] as FromHex>::Error>
where T: AsRef<[u8]>,

Implementors§