1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::{fmt, ops::Deref};
#[derive(Clone)]
pub struct Regex(regex::Regex);
impl Regex {
pub fn new(re: &str) -> Result<Self, regex::Error> {
regex::Regex::new(re).map(Regex)
}
}
impl From<regex::Regex> for Regex {
fn from(re: regex::Regex) -> Regex {
Regex(re)
}
}
impl From<&str> for Regex {
fn from(re: &str) -> Regex {
let re_compiled = regex::Regex::new(re)
.unwrap_or_else(|err| panic!("error compiling regex: {} ({})", re, err));
Regex(re_compiled)
}
}
impl Deref for Regex {
type Target = regex::Regex;
fn deref(&self) -> ®ex::Regex {
&self.0
}
}
impl fmt::Debug for Regex {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}