如何从 Rust MD5 (MD5) crate 中获取十六进制字符串?

How to get a hex string from Rust's MD-5 (MD5) crate?

根据此关于 WWW 身份验证的 RFC(在 HTTP 中使用)https://www.rfc-editor.org/rfc/rfc2617#page-7

For the purposes of this document, an MD5 digest of 128 bits is
represented as 32 ASCII printable characters. The bits in the 128 bit digest are converted from most significant to least significant bit,
four bits at a time to their ASCII presentation as follows. Each four bits is represented by its familiar hexadecimal notation from the
characters 0123456789abcdef. That is, binary 0000 gets represented by the character '0', 0001, by '1', and so on up to the representation
of 1111 as 'f'.

Rust 的 MD5 crate implements the Digest trait: https://docs.rs/digest/0.9.0/digest/trait.Digest.html 摘要为由 8 16 位切片组成的 GenericArray。

如何从 RFC 转换为这种哈希格式?为什么 md-5 crate 没有将摘要显示为十六进制值的简单功能?

板条箱 literal_hex 做相反的事情:将十六进制连接值的字符串转换为字节。

How do I convert for this hash format from RFC?

格式化为 the x (LowerHex) format specifier:

fn main() {
    let s = md5::Md5::new();
    println!("{:x}", s.finalize());
    // d41d8cd98f00b204e9800998ecf8427e
    println!("{:x}", md5::Md5::digest(b""));
    // d41d8cd98f00b204e9800998ecf8427e
}

作为the example for digest::Digest::digest shows.

Why doesn't the md-5 crate has a simple feature that displays the digest as hexadecimal values?

因为它内置于 Rust 中。