feat: add threadpool for iterator threads, bug fixes, tracing_flame support
This commit is contained in:
parent
e0072eff63
commit
5e924227b6
26 changed files with 472 additions and 228 deletions
|
@ -9,6 +9,7 @@ use std::{
|
|||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn millis_since_unix_epoch() -> u64 {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
@ -48,16 +49,19 @@ pub fn generate_keypair() -> Vec<u8> {
|
|||
}
|
||||
|
||||
/// Parses the bytes into an u64.
|
||||
#[tracing::instrument(skip(bytes))]
|
||||
pub fn u64_from_bytes(bytes: &[u8]) -> Result<u64, std::array::TryFromSliceError> {
|
||||
let array: [u8; 8] = bytes.try_into()?;
|
||||
Ok(u64::from_be_bytes(array))
|
||||
}
|
||||
|
||||
/// Parses the bytes into a string.
|
||||
#[tracing::instrument(skip(bytes))]
|
||||
pub fn string_from_bytes(bytes: &[u8]) -> Result<String, std::string::FromUtf8Error> {
|
||||
String::from_utf8(bytes.to_vec())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(length))]
|
||||
pub fn random_string(length: usize) -> String {
|
||||
thread_rng()
|
||||
.sample_iter(&rand::distributions::Alphanumeric)
|
||||
|
@ -67,6 +71,7 @@ pub fn random_string(length: usize) -> String {
|
|||
}
|
||||
|
||||
/// Calculate a new hash for the given password
|
||||
#[tracing::instrument(skip(password))]
|
||||
pub fn calculate_hash(password: &str) -> Result<String, argon2::Error> {
|
||||
let hashing_config = Config {
|
||||
variant: Variant::Argon2id,
|
||||
|
@ -77,6 +82,7 @@ pub fn calculate_hash(password: &str) -> Result<String, argon2::Error> {
|
|||
argon2::hash_encoded(password.as_bytes(), salt.as_bytes(), &hashing_config)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(iterators, check_order))]
|
||||
pub fn common_elements(
|
||||
mut iterators: impl Iterator<Item = impl Iterator<Item = Vec<u8>>>,
|
||||
check_order: impl Fn(&[u8], &[u8]) -> Ordering,
|
||||
|
@ -104,6 +110,7 @@ pub fn common_elements(
|
|||
/// Fallible conversion from any value that implements `Serialize` to a `CanonicalJsonObject`.
|
||||
///
|
||||
/// `value` must serialize to an `serde_json::Value::Object`.
|
||||
#[tracing::instrument(skip(value))]
|
||||
pub fn to_canonical_object<T: serde::Serialize>(
|
||||
value: T,
|
||||
) -> Result<CanonicalJsonObject, CanonicalJsonError> {
|
||||
|
@ -117,6 +124,7 @@ pub fn to_canonical_object<T: serde::Serialize>(
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(deserializer))]
|
||||
pub fn deserialize_from_str<
|
||||
'de,
|
||||
D: serde::de::Deserializer<'de>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue