Struct rand_regex::Regex
source · pub struct Regex { /* private fields */ }
Expand description
A random distribution which generates strings matching the specified regex.
Implementations
sourceimpl Regex
impl Regex
sourcepub fn is_utf8(&self) -> bool
pub fn is_utf8(&self) -> bool
Checks if the regex can only produce valid Unicode strings.
Examples
extern crate rand_regex;
extern crate regex_syntax;
let utf8_hir = regex_syntax::ParserBuilder::new()
.unicode(false)
.allow_invalid_utf8(true)
.build()
.parse(r"[\x00-\x7f]")
.unwrap();
let utf8_gen = rand_regex::Regex::with_hir(utf8_hir, 100).unwrap();
assert_eq!(utf8_gen.is_utf8(), true);
let non_utf8_hir = regex_syntax::ParserBuilder::new()
.unicode(false)
.allow_invalid_utf8(true)
.build()
.parse(r"[\x00-\xff]")
.unwrap();
let non_utf8_gen = rand_regex::Regex::with_hir(non_utf8_hir, 100).unwrap();
assert_eq!(non_utf8_gen.is_utf8(), false);
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the maximum length the string this regex can generate.
Examples
extern crate rand_regex;
let gen = rand_regex::Regex::compile(r"\d{4}-\d{2}-\d{2}", 100).unwrap();
assert_eq!(gen.capacity(), 34);
// each `\d` can occupy 4 bytes
sourcepub fn compile(pattern: &str, max_repeat: u32) -> Result<Self, Error>
pub fn compile(pattern: &str, max_repeat: u32) -> Result<Self, Error>
Compiles a regex pattern for string generation.
If you need to supply additional flags to the pattern, please use
Regex::with_hir()
instead.
The max_repeat
parameter gives the maximum extra repeat counts
the x*
, x+
and x{n,}
operators will become, e.g.
extern crate rand_regex;
let gen = rand_regex::Regex::compile("a{4,}", 100).unwrap();
// this will generate a string between 4 to 104 characters long.
assert_eq!(gen.capacity(), 104);
Trait Implementations
sourceimpl Distribution<String> for Regex
impl Distribution<String> for Regex
Auto Trait Implementations
impl RefUnwindSafe for Regex
impl Send for Regex
impl Sync for Regex
impl Unpin for Regex
impl UnwindSafe for Regex
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more