Start local server on client run
This commit is contained in:
23
rust/sea_battle_backend/src/utils/string_utils.rs
Normal file
23
rust/sea_battle_backend/src/utils/string_utils.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
/// Generate a random string of a given size
|
||||
pub fn rand_str(len: usize) -> String {
|
||||
thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.map(char::from)
|
||||
.take(len)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::utils::string_utils::rand_str;
|
||||
|
||||
#[test]
|
||||
fn test_rand_str() {
|
||||
let size = 10;
|
||||
let rand = rand_str(size);
|
||||
assert_eq!(size, rand.len());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user