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
: RepeatL
forRP
times.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 to a string, or panic in debug mode, work normally but slower in release mode.
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 random_str = RandHexStr::new_default().to_string_ext();
assert_eq!(random_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 moreSource§impl<const L: usize, const RP: usize, const LP: usize> Default for RandHexStr<L, RP, LP>
impl<const L: usize, const RP: usize, const LP: usize> Default for RandHexStr<L, RP, LP>
Source§fn default() -> RandHexStr<L, RP, LP>
fn default() -> RandHexStr<L, RP, LP>
Source§impl<const L: usize, const RP: usize, const LP: usize> StringExtT for RandHexStr<L, RP, LP>
impl<const L: usize, const RP: usize, const LP: usize> StringExtT for RandHexStr<L, RP, LP>
Source§fn with_prefix<P: StringExtT + Copy>(self, prefix: P) -> impl StringExtT
fn with_prefix<P: StringExtT + Copy>(self, prefix: P) -> impl StringExtT
Source§fn with_suffix<S: StringExtT + Copy>(self, suffix: S) -> impl StringExtT
fn with_suffix<S: StringExtT + Copy>(self, suffix: S) -> impl StringExtT
Source§fn to_string_ext(self) -> String
fn to_string_ext(self) -> String
Source§impl<const L: usize, const RP: usize, const LP: usize> StringT for RandHexStr<L, RP, LP>
impl<const L: usize, const RP: usize, const LP: usize> StringT for RandHexStr<L, RP, LP>
Source§fn encode_to_buf(self, string: &mut Vec<u8>)
fn encode_to_buf(self, string: &mut Vec<u8>)
Vec<u8>
).Source§fn encode_to_buf_with_separator(self, string: &mut Vec<u8>, separator: &str)
fn encode_to_buf_with_separator(self, string: &mut Vec<u8>, separator: &str)
Vec<u8>
) with a
separator. Read moreSource§fn encode_to_bytes_buf(self, string: &mut BytesMut)
fn encode_to_bytes_buf(self, string: &mut BytesMut)
bytes::BytesMut
).