title: How do I convert a string to hex in Rust?
body: <p>I want to convert a string of characters (a SHA256 hash) to hex in Rust: </p>
  
  <pre><code>extern crate crypto;
  extern crate rustc_serialize;
  
  use rustc_serialize::hex::ToHex;
  use crypto::digest::Digest;
  use crypto::sha2::Sha256;
  
  fn gen_sha256(hashme: &amp;str) -&gt; String {
      let mut sh = Sha256::new();
      sh.input_str(hashme);
  
      sh.result_str()
  }
  
  fn main() {
      let hash = gen_sha256("example");
  
      hash.to_hex()
  }
  </code></pre>
  
  <p>The compiler says:</p>
  
  <pre><code>error[E0599]: no method named `to_hex` found for type `std::string::String` in the current scope
    --&gt; src/main.rs:18:10
     |
  18 |     hash.to_hex()
     |          ^^^^^^
  </code></pre>
  
  <p>I can see this is true; it looks like <a href="https://docs.rs/rustc-serialize/0.3.24/rustc_serialize/hex/trait.ToHex.html" rel="noreferrer">it's only implemented for <code>[u8]</code></a>.</p>
  
  <p>What am I to do? Is there no method implemented to convert from a string to hex in Rust?</p>
  
  <p>My Cargo.toml dependencies:</p>
  
  <pre><code>[dependencies]
  rust-crypto = "0.2.36"
  rustc-serialize = "0.3.24"
  </code></pre>
  
  <hr>
  
  <p><strong>edit</strong> I just realized the string is <em>already</em> in hex format from the rust-crypto library. D'oh.</p>