title: Returning a hash as String rust
body: <p>I want to print the output from a hashing function to stdout. I use the groestl hash function but i suppose it works the same as sha or others. Doing it like this prints the hash as it should:</p>
  <pre><code>fn create_hash&lt;D: Digest&gt;(msg: &amp;str, mut hasher: D) -&gt; GenericArray&lt;u8, D::OutputSize&gt; {
    hasher.update(msg);
    hasher.finalize()
  }
  
  fn main() {
    let hasher = Groestl256::default();
    let res = create_hash(&quot;asdfasdf&quot;, hasher);
    println!(&quot;{:x}&quot;, res);
  }
  </code></pre>
  <p>Outputs: db102d374ae45b130ae49e91dcc7b648b86ba1a0415a32dcce7806d46f316460</p>
  <p>Now i want to do a match to make the other algorithms(Groestl512,...) also usable.</p>
  <pre><code>    let dig = match algorithm {
          HashTypes::groestl224 =&gt; {
              create_hash(message.as_ref().unwrap(), Groestl224::default())
          }
          HashTypes::groestl256 =&gt; {
              create_hash(message.as_ref().unwrap(), Groestl256::default())
          }
          HashTypes::groestl384 =&gt; {
              create_hash(message.as_ref().unwrap(), Groestl384::default())
          }
          HashTypes::groestl512 =&gt; {
              create_hash(message.as_ref().unwrap(), Groestl512::default())
          }
      };
      let res = HashGroestl::create_hash(&quot;asdfasdf&quot;, Groestl256::default());
      
      println!(&quot;Result: {:x}&quot;, res);
  </code></pre>
  <p>This results in the match arms having incompatible types due to different sizes of the returning array. I tried to bypass this by returning a String instead of the GenericArray.</p>
  <p>When i want to return a String from <code>create_hash</code> with <code>format!(&quot;{:x}&quot;, hasher.finalize())</code> results in following error:</p>
  <pre><code>cannot add `&lt;D as groestl::Digest&gt;::OutputSize` to `&lt;D as groestl::Digest&gt;::OutputSize`
  the trait `std::ops::Add` is not implemented for `&lt;D as groestl::Digest&gt;::OutputSize`
  required because of the requirements on the impl of `std::fmt::LowerHex` for `aes::cipher::generic_array::GenericArray&lt;u8, &lt;D as groestl::Digest&gt;::OutputSize&gt;`
  required by `std::fmt::LowerHex::fmt`
  </code></pre>
  <p>I also tried around with converting the array to a Vec or with .as_slice().</p>
  <p>So how can i either return a String like above or make the match arms compatible?</p>
  <p>EDIT: Okay, just found the solution in <a href="https://stackoverflow.com/questions/64326373/generic-function-to-compute-a-hash-digestdigest-trait-and-get-back-a-string">Generic function to compute a hash (digest::Digest trait) and get back a String</a> to return as a string.
  But the other part with making the match arms compatible still interests me, so if someone has an answer for that, you're welcome!</p>