Skip to content

Commit

Permalink
update build.rs & mac_address:validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypto-Spartan committed Jul 26, 2024
1 parent 0172599 commit 932f52b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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.
Expand All @@ -53,15 +53,19 @@ 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\
\tdfa::{dense, Automaton},\n\
\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<dense::DFA<&'static [u32]>> = Lazy::new(|| {\n\
\tstatic ALIGNED: &AlignAs<[u8], u32> = &AlignAs {\n\
\t\t_align: [],\n\
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/mac_address/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dense::DFA<&'static [u32]>> = Lazy::new(|| {
static ALIGNED: &AlignAs<[u8], u32> = &AlignAs {
_align: [],
Expand Down

0 comments on commit 932f52b

Please sign in to comment.