pub struct StringDef {
pub length: u32,
pub include_unicode: bool,
pub include_symbol: bool,
pub include_capital_letters: bool,
pub include_numbers: bool,
}Expand description
Defines the criteria for generating random strings.
Fields§
§length: u32The desired length of the generated string.
include_unicode: boolWhether to include Unicode characters in the generated string.
include_symbol: boolWhether to include symbols in the generated string.
include_capital_letters: boolWhether to include capital letters in the generated string.
include_numbers: boolWhether to include numeric characters in the generated string.
Implementations§
Source§impl StringDef
impl StringDef
Sourcepub fn from_randomizer(randomizer: &Randomizer) -> Self
pub fn from_randomizer(randomizer: &Randomizer) -> Self
Creates a StringDef from a given Randomizer.
Sourcepub fn generate(&self, rng: &mut dyn RngCore) -> String
pub fn generate(&self, rng: &mut dyn RngCore) -> String
Generates a random string based on the current configuration.
§Example
use crazy_train::{Randomizer, StringDef};
let string_def = StringDef::default();
let randomizer = Randomizer::with_seed(42);
let mut rng = randomizer.rng.borrow_mut();
assert_eq!(string_def.generate(&mut *rng), "noqkak");
assert_eq!(string_def.generate(&mut *rng), "twdayn");
assert_eq!(string_def.generate(&mut *rng), "kdnfan");Sourcepub fn contains_only_lowercase(s: &str) -> bool
pub fn contains_only_lowercase(s: &str) -> bool
Checks if a given string contains only lowercase letters.
§Example
use crazy_train::StringDef;
assert!(StringDef::contains_only_lowercase("test"));
assert!(!StringDef::contains_only_lowercase("1test"));
assert!(!StringDef::contains_only_lowercase("🙆test"));
assert!(!StringDef::contains_only_lowercase("#test"));
assert!(!StringDef::contains_only_lowercase("Test"));Sourcepub fn contains_unicode(s: &str) -> bool
pub fn contains_unicode(s: &str) -> bool
Checks if a given string contains any Unicode characters.
§Example
use crazy_train::StringDef;
assert!(!StringDef::contains_unicode("test"));
assert!(StringDef::contains_unicode("🙆Test"));Sourcepub fn contains_symbols(s: &str) -> bool
pub fn contains_symbols(s: &str) -> bool
Checks if a given string contains any symbols.
§Example
use crazy_train::StringDef;
assert!(!StringDef::contains_symbols("test"));
assert!(StringDef::contains_symbols("#Test"));Sourcepub fn contains_numbers(s: &str) -> bool
pub fn contains_numbers(s: &str) -> bool
Checks if a given string contains any numeric characters.
§Example
use crazy_train::StringDef;
assert!(!StringDef::contains_numbers("test"));
assert!(StringDef::contains_numbers("1Test"));Sourcepub fn contains_capital_letters(s: &str) -> bool
pub fn contains_capital_letters(s: &str) -> bool
Checks if a given string contains any capital letters.
§Example
use crazy_train::StringDef;
assert!(!StringDef::contains_capital_letters("test"));
assert!(StringDef::contains_capital_letters("Test"));Trait Implementations§
Auto Trait Implementations§
impl Freeze for StringDef
impl RefUnwindSafe for StringDef
impl Send for StringDef
impl Sync for StringDef
impl Unpin for StringDef
impl UnwindSafe for StringDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more