add non-allocating fixed-size random string generator
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
a5e85727b5
commit
43b0bb6a5e
1 changed files with 13 additions and 0 deletions
|
@ -3,6 +3,7 @@ use std::{
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use arrayvec::ArrayString;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
pub fn string(length: usize) -> String {
|
pub fn string(length: usize) -> String {
|
||||||
|
@ -13,6 +14,18 @@ pub fn string(length: usize) -> String {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn string_array<const LENGTH: usize>() -> ArrayString<LENGTH> {
|
||||||
|
let mut ret = ArrayString::<LENGTH>::new();
|
||||||
|
thread_rng()
|
||||||
|
.sample_iter(&rand::distributions::Alphanumeric)
|
||||||
|
.take(LENGTH)
|
||||||
|
.map(char::from)
|
||||||
|
.for_each(|c| ret.push(c));
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn timepoint_secs(range: Range<u64>) -> SystemTime {
|
pub fn timepoint_secs(range: Range<u64>) -> SystemTime {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue