provider and user connection management

This commit is contained in:
euzu
2025-04-28 19:52:59 +02:00
parent 8e04830c6b
commit 8fbbe4b15e
11 changed files with 139 additions and 69 deletions
+31
View File
@@ -1,3 +1,5 @@
use rand::Rng;
// other implementations like calculating text_distance on all titles took too much time
// we keep it now as simple as possible and less memory intensive.
pub fn get_title_group(text: &str) -> String {
@@ -41,3 +43,32 @@ pub fn get_trimmed_string(value: &Option<String>) -> Option<String> {
}
None
}
pub fn generate_random_string(length: usize) -> String {
let charset = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let mut rng = rand::rng();
let random_string: String = (0..length)
.map(|_| {
let idx = rng.random_range(0..charset.len());
charset[idx] as char
})
.collect();
random_string
}
#[cfg(test)]
mod test {
use std::collections::HashSet;
use crate::utils::string_utils::generate_random_string;
#[test]
fn test_generate_random_string() {
let mut strings = HashSet::new();
for _i in 0..100 {
strings.insert(generate_random_string(5));
}
assert_eq!(strings.len(), 100);
}
}