mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Load and compile template in proper function
Get rid of the unncessary closure.
This commit is contained in:
parent
1db84a3ec5
commit
085cc90599
@ -392,22 +392,14 @@ macro_rules! create_config {
|
||||
}
|
||||
|
||||
fn set_license_template(&mut self) {
|
||||
if !self.was_set().license_template_path() {
|
||||
return;
|
||||
if self.was_set().license_template_path() {
|
||||
let lt_path = self.license_template_path();
|
||||
match license::load_and_compile_template(<_path) {
|
||||
Ok(re) => self.license_template = Some(re),
|
||||
Err(msg) => eprintln!("Warning for license template file {:?}: {}",
|
||||
lt_path, msg),
|
||||
}
|
||||
}
|
||||
let lt_path = self.license_template_path();
|
||||
let try = || -> Result<Regex, LicenseError> {
|
||||
let mut lt_file = File::open(<_path)?;
|
||||
let mut lt_str = String::new();
|
||||
lt_file.read_to_string(&mut lt_str)?;
|
||||
let lt_parsed = TemplateParser::parse(<_str)?;
|
||||
Ok(Regex::new(<_parsed)?)
|
||||
};
|
||||
match try() {
|
||||
Ok(re) => self.license_template = Some(re),
|
||||
Err(msg) => eprintln!("Warning for license template file {:?}: {}",
|
||||
lt_path, msg),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::io;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
use regex;
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LicenseError {
|
||||
@ -210,6 +213,14 @@ impl TemplateParser {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_and_compile_template(path: &str) -> Result<Regex, LicenseError> {
|
||||
let mut lt_file = File::open(&path)?;
|
||||
let mut lt_str = String::new();
|
||||
lt_file.read_to_string(&mut lt_str)?;
|
||||
let lt_parsed = TemplateParser::parse(<_str)?;
|
||||
Ok(Regex::new(<_parsed)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::TemplateParser;
|
||||
|
@ -29,7 +29,6 @@ pub mod license;
|
||||
|
||||
use config::config_type::ConfigType;
|
||||
use config::file_lines::FileLines;
|
||||
use config::license::{LicenseError, TemplateParser};
|
||||
pub use config::lists::*;
|
||||
pub use config::options::*;
|
||||
use config::summary::Summary;
|
||||
|
Loading…
Reference in New Issue
Block a user