Skip to content

Commit 3b26105

Browse files
committed
use lazy-static regular expressions
1 parent c0392dc commit 3b26105

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdbook-goals/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ serde = "1.0.204"
1414
serde_json = "1.0.120"
1515
structopt = "0.3.26"
1616
walkdir = "2.5.0"
17-
rust_team_data = { git = "https://github.com/rust-lang/team" }
17+
rust_team_data = { git = "https://github.com/rust-lang/team" }
18+
lazy_static = "1.5.0"

mdbook-goals/src/goal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{collections::BTreeSet, path::PathBuf};
66
use anyhow::Context;
77
use regex::Regex;
88

9+
use crate::re::USERNAME;
910
use crate::team::{self, TeamName};
1011
use crate::util::{commas, markdown_files};
1112
use crate::{

mdbook-goals/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use walkdir::WalkDir;
99
mod goal;
1010
mod markwaydown;
1111
mod mdbook_preprocessor;
12+
mod re;
1213
mod rfc;
1314
mod team;
1415
mod util;

mdbook-goals/src/mdbook_preprocessor.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ impl Preprocessor for GoalPreprocessor {
3434
}
3535

3636
pub struct GoalPreprocessorWithContext<'c> {
37-
team_asks: Regex,
38-
goal_list: Regex,
39-
goal_count: Regex,
40-
username: Regex,
37+
team_asks: &'static Regex,
38+
goal_list: &'static Regex,
39+
goal_count: &'static Regex,
40+
username: &'static Regex,
4141
ctx: &'c PreprocessorContext,
4242
links: Vec<(String, String)>,
4343
linkifiers: Vec<(Regex, String)>,
@@ -113,10 +113,10 @@ impl<'c> GoalPreprocessorWithContext<'c> {
113113

114114
Ok(GoalPreprocessorWithContext {
115115
ctx,
116-
team_asks: Regex::new(r"<!-- TEAM ASKS -->")?,
117-
goal_list: Regex::new(r"<!-- GOALS `(.*)` -->")?,
118-
goal_count: Regex::new(r"<!-- #GOALS -->")?,
119-
username: Regex::new(r"@([-a-zA-Z0-9])+")?,
116+
team_asks: &re::TEAM_ASKS,
117+
goal_list: &re::GOAL_LIST,
118+
goal_count: &re::GOAL_COUNT,
119+
username: &re::USERNAME,
120120
links,
121121
linkifiers,
122122
display_names,

mdbook-goals/src/re.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use lazy_static::lazy_static;
2+
use regex::Regex;
3+
4+
lazy_static! {
5+
pub static ref TEAM_ASKS: Regex = Regex::new(r"<!-- TEAM ASKS -->").unwrap();
6+
}
7+
8+
lazy_static! {
9+
pub static ref GOAL_LIST: Regex = Regex::new(r"<!-- GOALS `(.*)` -->").unwrap();
10+
}
11+
12+
lazy_static! {
13+
pub static ref GOAL_COUNT: Regex = Regex::new(r"<!-- #GOALS -->").unwrap();
14+
}
15+
16+
lazy_static! {
17+
pub static ref USERNAME: Regex = Regex::new(r"@([-a-zA-Z0-9])+").unwrap();
18+
}

0 commit comments

Comments
 (0)