summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRyan Geary <rtgnj42@gmail.com>2020-03-15 16:30:59 -0400
committerRyan Geary <rtgnj42@gmail.com>2020-03-15 16:30:59 -0400
commitf87a3f16585eea8a0b545b9a77c9865cfc8aaccf (patch)
tree91a47e489591cca03e2c8fc28f65655f44074a9b /src
parentafb4bf47340f4ae6dbfb1dcfd199dcdacc42c378 (diff)
Use lazy_static for parse_choice regex
Diffstat (limited to 'src')
-rw-r--r--src/config.rs8
-rw-r--r--src/main.rs3
2 files changed, 8 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index 9814a85..afca365 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -32,6 +32,10 @@ pub struct Opt {
pub choice: Vec<Choice>,
}
+lazy_static! {
+ static ref PARSE_CHOICE_RE: Regex = Regex::new(r"^(\d*):(\d*)$").unwrap();
+}
+
pub struct Config {
pub opt: Opt,
pub separator: Regex,
@@ -77,9 +81,7 @@ impl Config {
}
pub fn parse_choice(src: &str) -> Result<Choice, ParseIntError> {
- let re = Regex::new(r"^(\d*):(\d*)$").unwrap();
-
- let cap = match re.captures_iter(src).next() {
+ let cap = match PARSE_CHOICE_RE.captures_iter(src).next() {
Some(v) => v,
None => match src.parse() {
Ok(x) => return Ok(Choice::new(x, x)),
diff --git a/src/main.rs b/src/main.rs
index e80f98f..b812462 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,9 @@ use std::fs::File;
use std::io::{self, Read, Write};
use structopt::StructOpt;
+#[macro_use]
+extern crate lazy_static;
+
mod choice;
mod config;
mod reader;