From 9ef82fe8864fb535a474d30577d74f4752d5f19a Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 22 Dec 2018 22:40:16 +0000 Subject: [PATCH] Run rustfmt (Rust 1.31.1) --- benches/eval.rs | 15 +++-- ffi/src/lib.rs | 9 ++- ffi/src/state.rs | 15 +++-- src/function/eval.rs | 20 ++++-- src/function/parse.rs | 150 +++++++++++++++++++++--------------------- src/lib.rs | 25 +++---- 6 files changed, 128 insertions(+), 106 deletions(-) diff --git a/benches/eval.rs b/benches/eval.rs index c6f3bed..52fa203 100644 --- a/benches/eval.rs +++ b/benches/eval.rs @@ -45,7 +45,8 @@ fn criterion_benchmark(c: &mut Criterion) { GameType::Tes4, "tests/testing-plugins/Oblivion/Data".into(), ".".into(), - ).with_active_plugins(&generate_active_plugins()); + ) + .with_active_plugins(&generate_active_plugins()); let expression = Expression::from_str("active(\"Blank.esm\")").unwrap(); @@ -59,7 +60,8 @@ fn criterion_benchmark(c: &mut Criterion) { GameType::Tes4, "tests/testing-plugins/Oblivion/Data".into(), ".".into(), - ).with_active_plugins(&generate_active_plugins()); + ) + .with_active_plugins(&generate_active_plugins()); let expression = Expression::from_str("active(\"Blank.*\")").unwrap(); @@ -82,7 +84,8 @@ fn criterion_benchmark(c: &mut Criterion) { GameType::Tes4, "tests/testing-plugins/Oblivion/Data".into(), ".".into(), - ).with_active_plugins(&generate_active_plugins()); + ) + .with_active_plugins(&generate_active_plugins()); let expression = Expression::from_str("many_active(\"Blank.*\")").unwrap(); @@ -109,7 +112,8 @@ fn criterion_benchmark(c: &mut Criterion) { GameType::Tes4, "tests/testing-plugins/Oblivion/Data".into(), ".".into(), - ).with_plugin_versions(&generate_plugin_versions()); + ) + .with_plugin_versions(&generate_plugin_versions()); let expression = Expression::from_str("version(\"Blank.esm\", \"5.0\", ==)").unwrap(); @@ -122,7 +126,8 @@ fn criterion_benchmark(c: &mut Criterion) { let state = State::new(GameType::Tes4, ".".into(), ".".into()); let expression = Expression::from_str( "version(\"tests/loot_api_win32/loot_api.dll\", \"0.13.8.0\", ==)", - ).unwrap(); + ) + .unwrap(); b.iter(|| { assert!(expression.eval(&state).unwrap()); diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 26eca71..29d5c68 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -38,7 +38,8 @@ pub unsafe extern "C" fn lci_condition_parse(condition: *const c_char) -> c_int LCI_OK } } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } #[no_mangle] @@ -71,7 +72,8 @@ pub unsafe extern "C" fn lci_condition_eval( Err(e) => handle_error(e), } } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } #[no_mangle] @@ -90,5 +92,6 @@ pub unsafe extern "C" fn lci_get_error_message(message: *mut *const c_char) -> c LCI_OK } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } diff --git a/ffi/src/state.rs b/ffi/src/state.rs index 20115b3..fb66318 100644 --- a/ffi/src/state.rs +++ b/ffi/src/state.rs @@ -61,7 +61,8 @@ pub unsafe extern "C" fn lci_state_create( LCI_OK } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } #[no_mangle] @@ -105,7 +106,8 @@ pub unsafe extern "C" fn lci_state_set_active_plugins( LCI_OK } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } #[no_mangle] @@ -142,7 +144,8 @@ pub unsafe extern "C" fn lci_state_set_plugin_versions( LCI_OK } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } #[no_mangle] @@ -178,7 +181,8 @@ pub unsafe extern "C" fn lci_state_set_crc_cache( }, } } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } #[no_mangle] @@ -195,5 +199,6 @@ pub unsafe extern "C" fn lci_state_clear_condition_cache(state: *mut lci_state) }, } } - }).unwrap_or(LCI_ERROR_PANICKED) + }) + .unwrap_or(LCI_ERROR_PANICKED) } diff --git a/src/function/eval.rs b/src/function/eval.rs index 73f3e3b..9692bc3 100644 --- a/src/function/eval.rs +++ b/src/function/eval.rs @@ -347,7 +347,8 @@ mod tests { copy( Path::new("tests/testing-plugins/Oblivion/Data/Blank.esp"), &state.data_path.join("Blank.esp.ghost"), - ).unwrap(); + ) + .unwrap(); let function = Function::FilePath(PathBuf::from("Blank.esp")); @@ -381,7 +382,8 @@ mod tests { copy( Path::new("Cargo.toml"), &state.data_path.join("Cargo.toml.ghost"), - ).unwrap(); + ) + .unwrap(); let function = Function::FilePath(PathBuf::from("Cargo.toml")); @@ -535,7 +537,7 @@ mod tests { #[test] fn function_checksum_eval_should_be_false_if_the_file_checksum_does_not_equal_the_given_checksum( -) { + ) { let function = Function::Checksum( PathBuf::from("tests/testing-plugins/Oblivion/Data/Blank.esm"), 0xDEADBEEF, @@ -565,7 +567,8 @@ mod tests { copy( Path::new("tests/testing-plugins/Oblivion/Data/Blank.esm"), &state.data_path.join("Blank.esm.ghost"), - ).unwrap(); + ) + .unwrap(); let function = Function::Checksum(PathBuf::from("Blank.esm"), 0x374E2A6F); @@ -581,7 +584,8 @@ mod tests { copy( Path::new("tests/testing-plugins/Oblivion/Data/Blank.bsa"), &state.data_path.join("Blank.bsa.ghost"), - ).unwrap(); + ) + .unwrap(); let function = Function::Checksum(PathBuf::from("Blank.bsa"), 0x22AB79D9); @@ -615,7 +619,8 @@ mod tests { copy( Path::new("tests/testing-plugins/Oblivion/Data/Blank.esm"), &state.data_path.join("Blank.esm"), - ).unwrap(); + ) + .unwrap(); let function = Function::Checksum(PathBuf::from("Blank.esm"), 0x374E2A6F); @@ -625,7 +630,8 @@ mod tests { copy( Path::new("tests/testing-plugins/Oblivion/Data/Blank.bsa"), &state.data_path.join("Blank.esm"), - ).unwrap(); + ) + .unwrap(); let function = Function::Checksum(PathBuf::from("Blank.esm"), 0x374E2A6F); diff --git a/src/function/parse.rs b/src/function/parse.rs index d9ef468..efb08a1 100644 --- a/src/function/parse.rs +++ b/src/function/parse.rs @@ -15,13 +15,14 @@ impl ComparisonOperator { input, operator: alt!( - tag!("==") => { |_| ComparisonOperator::Equal } | - tag!("!=") => { |_| ComparisonOperator::NotEqual } | - tag!("<=") => { |_| ComparisonOperator::LessThanOrEqual } | - tag!(">=") => { |_| ComparisonOperator::GreaterThanOrEqual } | - tag!("<") => { |_| ComparisonOperator::LessThan } | - tag!(">") => { |_| ComparisonOperator::GreaterThan } - ) >> (operator) + tag!("==") => { |_| ComparisonOperator::Equal } | + tag!("!=") => { |_| ComparisonOperator::NotEqual } | + tag!("<=") => { |_| ComparisonOperator::LessThanOrEqual } | + tag!(">=") => { |_| ComparisonOperator::GreaterThanOrEqual } | + tag!("<") => { |_| ComparisonOperator::LessThan } | + tag!(">") => { |_| ComparisonOperator::GreaterThan } + ) + >> (operator) ) } } @@ -180,74 +181,75 @@ impl Function { input, function: alt!( - delimited!( - fix_error!(ParsingError, tag!("file(\"")), - call!(parse_non_regex_path), - fix_error!(ParsingError, tag!("\")")) - ) => { - |path| Function::FilePath(path) - } | - delimited!( - fix_error!(ParsingError, tag!("file(\"")), - call!(parse_regex_path), - fix_error!(ParsingError, tag!("\"")) - ) => { - |(p, r)| Function::FileRegex(p, r) - } | - delimited!( - fix_error!(ParsingError, tag!("active(\"")), - call!(parse_non_regex_path), - fix_error!(ParsingError, tag!("\")")) - ) => { - |path| Function::ActivePath(path) - } | - delimited!( - fix_error!(ParsingError, tag!("active(\"")), - flat_map!(fix_error!(ParsingError, is_not!(INVALID_REGEX_PATH_CHARS)), parse_regex), - fix_error!(ParsingError, tag!("\"")) - ) => { - |r| Function::ActiveRegex(r) - } | - delimited!( - fix_error!(ParsingError, tag!("many(\"")), - call!(parse_regex_path), - fix_error!(ParsingError, tag!("\"")) - ) => { - |(p, r)| Function::Many(p, r) - } | - delimited!( - fix_error!(ParsingError, tag!("many_active(\"")), - flat_map!(fix_error!(ParsingError, is_not!(INVALID_REGEX_PATH_CHARS)), parse_regex), - fix_error!(ParsingError, tag!("\"")) - ) => { - |r| Function::ManyActive(r) - } | - delimited!( - fix_error!(ParsingError, tag!("version(")), - call!(parse_version_args), - fix_error!(ParsingError, tag!(")")) - ) => { - |(path, version, comparator)| { - Function::Version(path, version, comparator) + delimited!( + fix_error!(ParsingError, tag!("file(\"")), + call!(parse_non_regex_path), + fix_error!(ParsingError, tag!("\")")) + ) => { + |path| Function::FilePath(path) + } | + delimited!( + fix_error!(ParsingError, tag!("file(\"")), + call!(parse_regex_path), + fix_error!(ParsingError, tag!("\"")) + ) => { + |(p, r)| Function::FileRegex(p, r) + } | + delimited!( + fix_error!(ParsingError, tag!("active(\"")), + call!(parse_non_regex_path), + fix_error!(ParsingError, tag!("\")")) + ) => { + |path| Function::ActivePath(path) + } | + delimited!( + fix_error!(ParsingError, tag!("active(\"")), + flat_map!(fix_error!(ParsingError, is_not!(INVALID_REGEX_PATH_CHARS)), parse_regex), + fix_error!(ParsingError, tag!("\"")) + ) => { + |r| Function::ActiveRegex(r) + } | + delimited!( + fix_error!(ParsingError, tag!("many(\"")), + call!(parse_regex_path), + fix_error!(ParsingError, tag!("\"")) + ) => { + |(p, r)| Function::Many(p, r) + } | + delimited!( + fix_error!(ParsingError, tag!("many_active(\"")), + flat_map!(fix_error!(ParsingError, is_not!(INVALID_REGEX_PATH_CHARS)), parse_regex), + fix_error!(ParsingError, tag!("\"")) + ) => { + |r| Function::ManyActive(r) + } | + delimited!( + fix_error!(ParsingError, tag!("version(")), + call!(parse_version_args), + fix_error!(ParsingError, tag!(")")) + ) => { + |(path, version, comparator)| { + Function::Version(path, version, comparator) + } + } | + delimited!( + fix_error!(ParsingError, tag!("product_version(")), + call!(parse_version_args), + fix_error!(ParsingError, tag!(")")) + ) => { + |(path, version, comparator)| { + Function::ProductVersion(path, version, comparator) + } + } | + delimited!( + fix_error!(ParsingError, tag!("checksum(")), + call!(parse_checksum_args), + fix_error!(ParsingError, tag!(")")) + ) => { + |(path, crc)| Function::Checksum(path, crc) } - } | - delimited!( - fix_error!(ParsingError, tag!("product_version(")), - call!(parse_version_args), - fix_error!(ParsingError, tag!(")")) - ) => { - |(path, version, comparator)| { - Function::ProductVersion(path, version, comparator) - } - } | - delimited!( - fix_error!(ParsingError, tag!("checksum(")), - call!(parse_checksum_args), - fix_error!(ParsingError, tag!(")")) - ) => { - |(path, crc)| Function::Checksum(path, crc) - } - ) >> (function) + ) + >> (function) ) } } diff --git a/src/lib.rs b/src/lib.rs index 3ed09fe..ae79d4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,16 +237,17 @@ impl Condition { input, condition: alt!( - call!(Function::parse) => { - |f| Condition::Function(f) - } | - preceded!(fix_error!(ParsingError, ws!(tag!("not"))), call!(Function::parse)) => { - |f| Condition::InvertedFunction(f) - } | - delimited!(fix_error!(ParsingError, ws!(tag!("("))), call!(parse_expression), fix_error!(ParsingError, ws!(tag!(")")))) => { - |e| Condition::Expression(e) - } - ) >> (condition) + call!(Function::parse) => { + |f| Condition::Function(f) + } | + preceded!(fix_error!(ParsingError, ws!(tag!("not"))), call!(Function::parse)) => { + |f| Condition::InvertedFunction(f) + } | + delimited!(fix_error!(ParsingError, ws!(tag!("("))), call!(parse_expression), fix_error!(ParsingError, ws!(tag!(")")))) => { + |e| Condition::Expression(e) + } + ) + >> (condition) ) } } @@ -380,7 +381,7 @@ mod tests { #[test] fn game_type_is_plugin_filename_should_be_true_for_esl_dot_ghost_for_tes5se_tes5vr_fo4_and_fo4vr( -) { + ) { let filename = Path::new("Blank.esl.ghost"); assert!(GameType::Tes5se.is_plugin_filename(filename)); @@ -415,7 +416,7 @@ mod tests { #[test] fn game_type_is_plugin_filename_should_be_false_for_non_esp_esm_esl_dot_ghost_for_all_game_types( -) { + ) { let filename = Path::new("Blank.txt.ghost"); assert!(!GameType::Tes4.is_plugin_filename(filename));