diff --git a/Cargo.lock b/Cargo.lock index bf23157..0c24779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -627,6 +627,7 @@ dependencies = [ "anymap", "env_logger", "image", + "lazy_static", "lru-cache", "n5", "ndarray", diff --git a/Cargo.toml b/Cargo.toml index ac9ef0b..44d4cee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ actix-web = "4" actix-cors = "0.6" anymap = "0.12" env_logger = "0.9" +lazy_static = "1" lru-cache = "0.1.2" n5 = "0.7" ndarray = "0.13" diff --git a/src/main.rs b/src/main.rs index 2f8ddd8..7ffcc51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,12 +92,15 @@ impl FromStr for TileImageSpec { type Err = TileImageSpecError; fn from_str(s: &str) -> Result { - let re = regex::Regex::new(concat!( - r"^(?P.*)/(?P\d+_\d+(_\d+)?)/", - r"(?P\d+_\d+)(?P(/\d+)+)\.(?P.+)$" - )) - .expect("Impossible: regex is valid"); - let caps = re.captures(s).ok_or(TileImageSpecError::MalformedPath)?; + lazy_static::lazy_static! { + static ref RE: regex::Regex = regex::Regex::new(concat!( + r"^(?P.*)/(?P\d+_\d+(_\d+)?)/", + r"(?P\d+_\d+)(?P(/\d+)+)\.(?P.+)$" + )) + .expect("Impossible: regex is valid"); + } + + let caps = RE.captures(s).ok_or(TileImageSpecError::MalformedPath)?; let n5_dataset = caps["dataset"].into(); let mut sd_vals = caps["slicing"].split('_').map(u32::from_str);