MD5 hash in Rust

Viewed 4074

I'm trying to create an md5-hash from a string in Rust.

This is what I have been able to find in the documentation:

let digest = md5::compute(b"abcdefghijklmnopqrstuvwxyz");

assert_eq!(format!("{:x}", digest), "c3fcd3d76192e4007dfb496cca67e13b");

So now my code is:

fn main(){
    let digest = md5::compute(b"abcdefghijklmnopqrstuvwxyz");
    assert_eq!(format!("{:x}", digest), "c3fcd3d76192e4007dfb496cca67e13b");
}

I can't figure out how to import the md5 lib, so I am getting this error message:

use of undeclared type or module `md5`
1 Answers

You should add use md5 import at the top of your file:

use md5;

fn main(){
    let digest = md5::compute(b"abcdefghijklmnopqrstuvwxyz");
    assert_eq!(format!("{:x}", digest), "c3fcd3d76192e4007dfb496cca67e13b");
}

playground

Related