diff --git a/src/hash/mod.rs b/src/hash/mod.rs index da74a13..c0f52fc 100644 --- a/src/hash/mod.rs +++ b/src/hash/mod.rs @@ -1,5 +1,9 @@ pub mod md5 { use md5::Digest; + + /// 计算输入内容的MD5哈希值,返回十六进制字符串。 + /// + /// - `input` 输入内容。 pub fn hash>(input: T) -> String { let mut hasher = md5::Md5::new(); hasher.update(input); @@ -7,6 +11,9 @@ pub mod md5 { crate::serialize::to_hex(result.as_slice()) } + /// 计算输入内容的MD5哈希值,返回字节向量。 + /// + /// - `input` 输入内容。 pub fn hash_hex>(input: T) -> Vec { let mut hasher = md5::Md5::new(); hasher.update(input); @@ -17,6 +24,10 @@ pub mod md5 { pub mod sha1 { use sha1::Digest; + + /// 计算输入内容的SHA1哈希值,返回十六进制字符串。 + /// + /// - `input` 输入内容。 pub fn hash>(input: T) -> String { let mut hasher = sha1::Sha1::new(); hasher.update(input); @@ -24,6 +35,9 @@ pub mod sha1 { crate::serialize::to_hex(result.as_slice()) } + /// 计算输入内容的SHA1哈希值,返回字节向量。 + /// + /// - `input` 输入内容。 pub fn hash_hex>(input: T) -> Vec { let mut hasher = sha1::Sha1::new(); hasher.update(input); @@ -33,6 +47,10 @@ pub mod sha1 { } pub mod sha512 { + + /// 计算输入内容的SHA512哈希值,返回十六进制字符串。 + /// + /// - `input` 输入内容。 pub fn hash>(input: T) -> String { let mut hasher = hmac_sha512::Hash::new(); hasher.update(input); @@ -40,6 +58,9 @@ pub mod sha512 { crate::serialize::to_hex(result.as_slice()) } + /// 计算输入内容的SHA512哈希值,返回字节向量。 + /// + /// - `input` 输入内容。 pub fn hash_hex>(input: T) -> Vec { let mut hasher = hmac_sha512::Hash::new(); hasher.update(input); @@ -56,6 +77,10 @@ pub mod image_hash { Detailed = 32, } + /// 计算输入图片的区块感知哈希值,返回十六进制字符串。 + /// + /// - `input` 输入图片。 + /// - `precision` 感知精度,感知精度越高,越能区分图片的细节,但是计算时间也越长。 pub fn hash_image>>( input: &T, precision: Precision, diff --git a/src/serial_code/mod.rs b/src/serial_code/mod.rs index dceebe2..7525964 100644 --- a/src/serial_code/mod.rs +++ b/src/serial_code/mod.rs @@ -1,6 +1,7 @@ pub mod hail; pub mod uuid { + /// 生成一个UUID v4字符串。 pub fn new() -> Box { Box::from(uuid::Uuid::new_v4().to_string()) } @@ -8,6 +9,8 @@ pub mod uuid { pub mod short_uuid { const STR_SRC: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + + /// 生成一个基于UUID v4的短UUID字符串。 pub fn new(length: i16) -> Box { let length = if length < 2 { 2