Skip to content

Commit

Permalink
Make spec path regex static
Browse files Browse the repository at this point in the history
Closes #45.
  • Loading branch information
aschampion committed Jun 13, 2022
1 parent 31f8b74 commit 662aaeb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 9 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ impl FromStr for TileImageSpec {
type Err = TileImageSpecError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let re = regex::Regex::new(concat!(
r"^(?P<dataset>.*)/(?P<slicing>\d+_\d+(_\d+)?)/",
r"(?P<tile_size>\d+_\d+)(?P<coords>(/\d+)+)\.(?P<format>.+)$"
))
.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<dataset>.*)/(?P<slicing>\d+_\d+(_\d+)?)/",
r"(?P<tile_size>\d+_\d+)(?P<coords>(/\d+)+)\.(?P<format>.+)$"
))
.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);
Expand Down

0 comments on commit 662aaeb

Please sign in to comment.