rust_regex_dsl_creator/
basic_impls.rs

1use crate::ToDsl;
2use crate::ast_impl::Builder;
3use crate::printer::Printer;
4use regex::Error;
5use regex::Regex;
6use regex_syntax::ast::parse::Parser;
7
8impl<T: ToString> ToDsl for T {
9    fn to_dsl(&self) -> Result<String, Error> {
10        let str = self.to_string();
11        Regex::new(&str)?;
12        let mut parser = Parser::new();
13        // This must pass since the regular expression is valid
14        let ast = parser.parse(&str).unwrap();
15        let mut printer = Printer::new();
16        ast.print_ast(&mut printer);
17        Ok(printer.to_string())
18    }
19}