const_hex::traits

Trait FromHex

Source
pub trait FromHex: Sized {
    type Error;

    // Required method
    fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error>;
}
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§

Source

type Error

The associated error which can be returned from parsing.

Required Methods§

Source

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

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).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromHex for Box<[i8]>

Available on crate feature alloc only.
Source§

type Error = FromHexError

Source§

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

Source§

impl FromHex for Box<[u8]>

Available on crate feature alloc only.
Source§

type Error = FromHexError

Source§

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

Source§

impl FromHex for Vec<i8>

Available on crate feature alloc only.
Source§

type Error = FromHexError

Source§

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

Source§

impl FromHex for Vec<u8>

Available on crate feature alloc only.
Source§

type Error = FromHexError

Source§

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

Source§

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

Available on crate feature alloc only.
Source§

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

Source§

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

Source§

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

Available on crate feature alloc only.
Source§

type Error = <T as FromHex>::Error

Source§

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

Source§

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

Available on crate feature alloc only.
Source§

type Error = <T as FromHex>::Error

Source§

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

Source§

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

Available on crate feature alloc only.
Source§

type Error = <T as FromHex>::Error

Source§

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

Source§

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

Source§

type Error = FromHexError

Source§

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

Source§

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

Source§

type Error = FromHexError

Source§

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

Implementors§