From f87a3f16585eea8a0b545b9a77c9865cfc8aaccf Mon Sep 17 00:00:00 2001 From: Ryan Geary Date: Sun, 15 Mar 2020 16:30:59 -0400 Subject: Use lazy_static for parse_choice regex --- src/config.rs | 8 +++++--- src/main.rs | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') 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, } +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 { - 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; -- cgit v1.2.3