Switch to uuid7

This commit is contained in:
Ellie Huxtable 2023-03-13 21:39:31 +00:00
parent 1638cb57cb
commit 1f21fa3338
2 changed files with 15 additions and 2 deletions

2
.cargo/config.toml Normal file
View File

@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "uuid_unstable"]

View File

@ -3,8 +3,19 @@ use std::path::PathBuf;
use chrono::NaiveDate;
use uuid::Uuid;
pub fn uuid_v4() -> String {
Uuid::new_v4().as_simple().to_string()
pub fn uuid_v7() -> String {
Uuid::now_v7().as_simple().to_string()
}
pub fn hash_str(string: &str) -> String {
hash_bytes(string.as_bytes())
}
pub fn hash_bytes(buf: &[u8]) -> String {
use sha2::{Digest, Sha256};
let mut hasher = Sha256::new();
hasher.update(buf);
hex::encode(hasher.finalize())
}
// TODO: more reliable, more tested