mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-08 08:52:05 +02:00
provider and user connection management
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user