use std::{env, fs, path::Path}; use fancy_regex::Regex as Fancy; use regex::Regex; use serde::Deserialize; #[allow(dead_code)] #[derive(Deserialize, Debug)] struct Data { #[serde(rename(deserialize = "Name"))] name: String, #[serde(rename(deserialize = "Regex"))] regex: String, #[serde(skip_deserializing)] boundaryless: String, plural_name: bool, #[serde(rename(deserialize = "Description"))] description: Option<&'static str>, #[serde(rename(deserialize = "Exploit"))] exploit: Option, #[serde(rename(deserialize = "Rarity"))] rarity: f32, #[serde(rename(deserialize = "URL"))] url: Option<&'static str>, #[serde(rename(deserialize = "Tags"))] tags: Vec<&'static str>, } fn main() { let mut data: Vec = serde_json::from_str(include_str!("./src/data/regex.json")).unwrap(); data.iter_mut().for_each(|d| { d.boundaryless = Fancy::new(r"(?; {count}] = [{regex_str}]; static BOUNDARYLESS_REGEX: [Lazy; {count}] = [{boundaryless_regex_str}]; "# ); let regex_dest_path = Path::new(&out_dir).join("regex_data.rs"); fs::write(regex_dest_path, final_str).unwrap(); }