pub trait FromHex {
// Required method
fn from_hex(&self) -> Result<Vec<u8>, FromHexError>;
}Expand description
A trait for converting hexadecimal encoded values
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl FromHex for str
impl FromHex for str
Source§fn from_hex(&self) -> Result<Vec<u8>, FromHexError>
fn from_hex(&self) -> Result<Vec<u8>, FromHexError>
Convert any hexadecimal encoded string (literal, @, &, or ~)
to the byte values it encodes.
You can use the String::from_utf8 function to turn a
Vec<u8> into a string with characters corresponding to those values.
§Example
This converts a string literal to hexadecimal and back.
extern crate rustc_serialize;
use rustc_serialize::hex::{FromHex, ToHex};
fn main () {
let hello_str = "Hello, World".as_bytes().to_hex();
println!("{}", hello_str);
let bytes = hello_str.from_hex().unwrap();
println!("{:?}", bytes);
let result_str = String::from_utf8(bytes).unwrap();
println!("{}", result_str);
}