pub enum Error {
Anchor,
Syntax(Box<Error>),
}
Expand description
Error returned by Regex::compile()
and Regex::with_hir()
.
§Examples
let gen = rand_regex::Regex::compile(r"^.{4}\b.{4}$", 100);
assert_eq!(gen.err(), Some(rand_regex::Error::Anchor));
Variants§
Anchor
Anchors (^
, $
, \A
, \z
) and word boundary assertions (\b
, \B
)
are not supported.
If you really need to include anchors, please consider using rejection sampling e.g.
use rand::Rng;
// create the generator without the anchor
let gen = rand_regex::Regex::compile(r".{4}.{4}", 100).unwrap();
// later filter the sampled result using a regex with the anchor
let filter_regex = regex::Regex::new(r"^.{4}\b.{4}$").unwrap();
let _sample = rand::thread_rng()
.sample_iter::<String, _>(&gen)
.filter(|s| filter_regex.is_match(s))
.next()
.unwrap();
Syntax(Box<Error>)
The input regex has a syntax error.
§Examples
let gen = rand_regex::Regex::compile(r"(", 100);
assert!(match gen {
Err(rand_regex::Error::Syntax(_)) => true,
_ => false,
});
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
impl Eq for Error
impl StructuralPartialEq for Error
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
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