pub struct RandHexStr<const L: usize = 16, const RP: usize = 1, const LP: usize = 0>;Expand description
Randon hex-like string, with fix length.
For better performance, the underlying random number is generated by
xorshift algorithm then converted to hex string with NumStr.
By default, the length is 16.
§Generic Parameters
L: The length of the string. Max 16 (u64).RP: RepeatLforRPtimes.LP: Lefted length. Max 16.
For example, if you need a string with length 56, you may specify L as 16,
RP as 56 / 16 = 3, and LP as 56 % 16 = 8.
Since #![feature(generic_const_exprs)] is not stable, we have to make use
of these complex const generics.
Notice: will check if params are valid when you push this into the
StringExt, or panic in debug mode, work normally but
slower in release mode (unless feature feat-unsafe is enabled and you will
come across with UB).
Implementations§
Source§impl RandHexStr
impl RandHexStr
Sourcepub const fn new_default() -> Self
pub const fn new_default() -> Self
Create a new RandHexStr and generate simple random hex-like string
with length 16 (default).
§Example
let rand_str = RandHexStr::new_default().to_string_ext();
assert_eq!(rand_str.len(), 16);Source§impl<const L: usize, const RP: usize, const LP: usize> RandHexStr<L, RP, LP>
impl<const L: usize, const RP: usize, const LP: usize> RandHexStr<L, RP, LP>
Sourcepub const fn with_l<const NL: usize>(self) -> RandHexStr<NL, RP, LP>
pub const fn with_l<const NL: usize>(self) -> RandHexStr<NL, RP, LP>
Set L.
You may prefer RandHexStr::<L, RP, LP>::new.
Sourcepub const fn with_rp<const NRP: usize>(self) -> RandHexStr<L, NRP, LP>
pub const fn with_rp<const NRP: usize>(self) -> RandHexStr<L, NRP, LP>
Set RP.
You may prefer RandHexStr::<L, RP, LP>::new.
Sourcepub const fn with_lp<const NLP: usize>(self) -> RandHexStr<L, RP, NLP>
pub const fn with_lp<const NLP: usize>(self) -> RandHexStr<L, RP, NLP>
Set LP.
You may prefer RandHexStr::<L, RP, LP>::new.
Trait Implementations§
Source§impl<const L: usize, const RP: usize, const LP: usize> Clone for RandHexStr<L, RP, LP>
impl<const L: usize, const RP: usize, const LP: usize> Clone for RandHexStr<L, RP, LP>
Source§fn clone(&self) -> RandHexStr<L, RP, LP>
fn clone(&self) -> RandHexStr<L, RP, LP>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more