How to convert a string to hex in Rust?
Encoding and decoding data into/from hexadecimal representation. In order to use this crate, you have to add it under [dependencies] to your Cargo.toml[dependencies]
hex = "0.4"
By default this will import std, if you are working in a no_std environment you can turn this off by adding the following
[dependencies]
hex = { version = "0.4", default-features = false }
Encoding a String
let hex_string = hex::encode("Hello world!");
println!("{}", hex_string); // Prints "48656c6c6f20776f726c6421"
Decoding a String
let decoded_string = hex::decode("48656c6c6f20776f726c6421");
println!("{}", decoded_string); // Prints "Hello world!"