From 932f52b5772975929b7f78ddebd3bc5f0d116b9e Mon Sep 17 00:00:00 2001 From: Crypto-Spartan Date: Fri, 26 Jul 2024 04:08:19 -0400 Subject: [PATCH] update build.rs & mac_address:validation --- build.rs | 14 ++++++++++---- src/mac_address/validation/mod.rs | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 38282b0..de83ce9 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,7 @@ use regex_automata::{ }; use std::{fs, io}; -const MAC_ADDR_REGEX: &str = "^(?:(?:[0-9A-Fa-f]{2}:){5}|(?:[0-9A-Fa-f]{2}-){5})[0-9A-Fa-f]{2}$"; +const MAC_ADDR_REGEX_STR: &str = "^(?:(?:[0-9A-Fa-f]{2}:){5}|(?:[0-9A-Fa-f]{2}-){5})[0-9A-Fa-f]{2}$"; fn main() -> io::Result<()> { #[cfg(windows)] @@ -34,7 +34,7 @@ fn main() -> io::Result<()> { .prefilter(pre) .minimize(true), ) - .build(MAC_ADDR_REGEX) + .build(MAC_ADDR_REGEX_STR) .expect("dense DFA"); // Write the contents of the DFA *without* the initial padding. @@ -53,7 +53,7 @@ fn main() -> io::Result<()> { ) .unwrap(); - let autogenerated_mod_string = "\ + let autogenerated_mod_header = "\ // DO NOT EDIT THIS FILE. IT WAS AUTOMATICALLY GENERATED BY THE BUILD SCRIPT\n\n\ use once_cell::sync::Lazy;\n\ use regex_automata::{\n\ @@ -61,7 +61,11 @@ fn main() -> io::Result<()> { \tutil::wire::AlignAs,\n\ \tAnchored, Input,\n\ };\n\ - \n\ + \n"; + + let const_regex_str = format!(r#"pub(crate) const MAC_ADDR_REGEX_STR: &str = "{MAC_ADDR_REGEX_STR}";"#); + + let autogenerated_mod_body = "\n\n\ pub static MAC_ADDR_REGEX: Lazy> = Lazy::new(|| {\n\ \tstatic ALIGNED: &AlignAs<[u8], u32> = &AlignAs {\n\ \t\t_align: [],\n\ @@ -81,6 +85,8 @@ fn main() -> io::Result<()> { \t\t.map_or(false, |x| x.is_some())\n\ }"; + let autogenerated_mod_string = format!("{autogenerated_mod_header}{const_regex_str}{autogenerated_mod_body}"); + fs::write( format!("{mac_addr_validation_dir}/mod.rs"), autogenerated_mod_string, diff --git a/src/mac_address/validation/mod.rs b/src/mac_address/validation/mod.rs index 215973c..1b9e3aa 100644 --- a/src/mac_address/validation/mod.rs +++ b/src/mac_address/validation/mod.rs @@ -7,6 +7,8 @@ use regex_automata::{ Anchored, Input, }; +pub(crate) const MAC_ADDR_REGEX_STR: &str = "^(?:(?:[0-9A-Fa-f]{2}:){5}|(?:[0-9A-Fa-f]{2}-){5})[0-9A-Fa-f]{2}$"; + pub static MAC_ADDR_REGEX: Lazy> = Lazy::new(|| { static ALIGNED: &AlignAs<[u8], u32> = &AlignAs { _align: [],