From 4b5fc80028a1f13fa881bf26afdac7ad0a9f5aed Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Mon, 9 Mar 2026 17:50:03 +0000 Subject: [PATCH] Reformat code for consistent style and readability --- crates/bough-cli/src/config.rs | 111 ++++++++++++++------- crates/bough-cli/src/render.rs | 84 +++++++++++++--- crates/bough-core/src/base.rs | 8 +- crates/bough-core/src/facet_disk_store.rs | 9 +- crates/bough-core/src/lib.rs | 2 +- crates/bough-core/src/mutant.rs | 36 +++++-- crates/bough-core/src/mutation.rs | 30 ++++-- crates/bough-core/src/session.rs | 1 - crates/bough-core/src/twig.rs | 5 +- crates/bough-core/src/workspace.rs | 8 +- crates/bough-typed-hash/src/lib.rs | 5 +- crates/bough-typed-hash/src/tests.rs | 83 ++++++++++++--- crates/bough-typed-hash/src/unvalidated.rs | 5 +- 13 files changed, 286 insertions(+), 101 deletions(-) diff --git a/crates/bough-cli/src/config.rs b/crates/bough-cli/src/config.rs index ff814ff3..21ab539d 100644 --- a/crates/bough-cli/src/config.rs +++ b/crates/bough-cli/src/config.rs @@ -1047,10 +1047,7 @@ exclude = [] #[test] fn test_cmd_parsed() { let cli = parse_ok(&["run"], MINIMAL_TOML); - assert_eq!( - bough_core::Config::get_test_cmd(&cli.config), - "echo test" - ); + assert_eq!(bough_core::Config::get_test_cmd(&cli.config), "echo test"); } #[test] @@ -1287,10 +1284,7 @@ cmd = "npm test" #[test] fn init_cmd_none_by_default() { let cli = parse_ok(&["run"], MINIMAL_TOML); - assert_eq!( - bough_core::Config::get_init_cmd(&cli.config), - None - ); + assert_eq!(bough_core::Config::get_init_cmd(&cli.config), None); } #[test] @@ -1360,10 +1354,7 @@ NODE_ENV = "" #[test] fn reset_cmd_none_by_default() { let cli = parse_ok(&["run"], MINIMAL_TOML); - assert_eq!( - bough_core::Config::get_reset_cmd(&cli.config), - None - ); + assert_eq!(bough_core::Config::get_reset_cmd(&cli.config), None); } #[test] @@ -1458,7 +1449,10 @@ cmd = "npm run clean" let c = &cli.config; assert_eq!(bough_core::Config::get_test_cmd(c), "npm test"); - assert_eq!(bough_core::Config::get_test_pwd(c), std::path::PathBuf::from("build")); + assert_eq!( + bough_core::Config::get_test_pwd(c), + std::path::PathBuf::from("build") + ); assert_eq!( bough_core::Config::get_test_env(c), HashMap::from([ @@ -1467,20 +1461,38 @@ cmd = "npm run clean" ("JEST_WORKERS".to_string(), "4".to_string()), ]) ); - assert_eq!(bough_core::Config::get_test_timeout_absolute(c), Some(chrono::Duration::seconds(60))); + assert_eq!( + bough_core::Config::get_test_timeout_absolute(c), + Some(chrono::Duration::seconds(60)) + ); assert_eq!(bough_core::Config::get_test_timeout_relative(c), Some(3.0)); - assert_eq!(bough_core::Config::get_init_cmd(c), Some("npm install".to_string())); - assert_eq!(bough_core::Config::get_init_pwd(c), std::path::PathBuf::from("setup")); + assert_eq!( + bough_core::Config::get_init_cmd(c), + Some("npm install".to_string()) + ); + assert_eq!( + bough_core::Config::get_init_pwd(c), + std::path::PathBuf::from("setup") + ); assert_eq!( bough_core::Config::get_init_env(c), HashMap::from([("CI".to_string(), "1".to_string())]) ); - assert_eq!(bough_core::Config::get_init_timeout_absolute(c), Some(chrono::Duration::seconds(30))); + assert_eq!( + bough_core::Config::get_init_timeout_absolute(c), + Some(chrono::Duration::seconds(30)) + ); assert_eq!(bough_core::Config::get_init_timeout_relative(c), Some(3.0)); - assert_eq!(bough_core::Config::get_reset_cmd(c), Some("npm run clean".to_string())); - assert_eq!(bough_core::Config::get_reset_pwd(c), std::path::PathBuf::from("build")); + assert_eq!( + bough_core::Config::get_reset_cmd(c), + Some("npm run clean".to_string()) + ); + assert_eq!( + bough_core::Config::get_reset_pwd(c), + std::path::PathBuf::from("build") + ); assert_eq!( bough_core::Config::get_reset_env(c), HashMap::from([ @@ -1488,7 +1500,10 @@ cmd = "npm run clean" ("NODE_ENV".to_string(), "test".to_string()), ]) ); - assert_eq!(bough_core::Config::get_reset_timeout_absolute(c), Some(chrono::Duration::seconds(30))); + assert_eq!( + bough_core::Config::get_reset_timeout_absolute(c), + Some(chrono::Duration::seconds(30)) + ); assert_eq!(bough_core::Config::get_reset_timeout_relative(c), Some(3.0)); } } @@ -1511,7 +1526,8 @@ impl HasPhaseOverrides for PhaseConfig { impl Config { fn phase_overrides(&self, phase: &Option) -> PhaseOverrides { - phase.as_ref() + phase + .as_ref() .map(|p| p.phase_overrides().clone()) .unwrap_or_default() } @@ -1519,7 +1535,8 @@ impl Config { impl PhaseOverrides { fn resolve_pwd(&self, global: &PhaseOverrides) -> PathBuf { - self.pwd.as_deref() + self.pwd + .as_deref() .or(global.pwd.as_deref()) .map(PathBuf::from) .unwrap_or_else(|| PathBuf::from(".")) @@ -1540,13 +1557,17 @@ impl PhaseOverrides { } fn resolve_timeout_absolute(&self, global: &PhaseOverrides) -> Option { - self.timeout.as_ref().and_then(|t| t.absolute) + self.timeout + .as_ref() + .and_then(|t| t.absolute) .or_else(|| global.timeout.as_ref().and_then(|t| t.absolute)) .map(|secs| chrono::Duration::seconds(secs as i64)) } fn resolve_timeout_relative(&self, global: &PhaseOverrides) -> Option { - self.timeout.as_ref().and_then(|t| t.relative) + self.timeout + .as_ref() + .and_then(|t| t.relative) .or_else(|| global.timeout.as_ref().and_then(|t| t.relative)) } } @@ -1590,23 +1611,31 @@ impl bough_core::Config for Config { } fn get_test_cmd(&self) -> String { - self.test.as_ref().expect("test.cmd is required").cmd.clone() + self.test + .as_ref() + .expect("test.cmd is required") + .cmd + .clone() } fn get_test_pwd(&self) -> std::path::PathBuf { - self.phase_overrides(&self.test).resolve_pwd(&self.phase_defaults) + self.phase_overrides(&self.test) + .resolve_pwd(&self.phase_defaults) } fn get_test_env(&self) -> HashMap { - self.phase_overrides(&self.test).resolve_env(&self.phase_defaults) + self.phase_overrides(&self.test) + .resolve_env(&self.phase_defaults) } fn get_test_timeout_absolute(&self) -> Option { - self.phase_overrides(&self.test).resolve_timeout_absolute(&self.phase_defaults) + self.phase_overrides(&self.test) + .resolve_timeout_absolute(&self.phase_defaults) } fn get_test_timeout_relative(&self) -> Option { - self.phase_overrides(&self.test).resolve_timeout_relative(&self.phase_defaults) + self.phase_overrides(&self.test) + .resolve_timeout_relative(&self.phase_defaults) } fn get_init_cmd(&self) -> Option { @@ -1614,19 +1643,23 @@ impl bough_core::Config for Config { } fn get_init_pwd(&self) -> std::path::PathBuf { - self.phase_overrides(&self.init).resolve_pwd(&self.phase_defaults) + self.phase_overrides(&self.init) + .resolve_pwd(&self.phase_defaults) } fn get_init_env(&self) -> HashMap { - self.phase_overrides(&self.init).resolve_env(&self.phase_defaults) + self.phase_overrides(&self.init) + .resolve_env(&self.phase_defaults) } fn get_init_timeout_absolute(&self) -> Option { - self.phase_overrides(&self.init).resolve_timeout_absolute(&self.phase_defaults) + self.phase_overrides(&self.init) + .resolve_timeout_absolute(&self.phase_defaults) } fn get_init_timeout_relative(&self) -> Option { - self.phase_overrides(&self.init).resolve_timeout_relative(&self.phase_defaults) + self.phase_overrides(&self.init) + .resolve_timeout_relative(&self.phase_defaults) } fn get_reset_cmd(&self) -> Option { @@ -1634,19 +1667,23 @@ impl bough_core::Config for Config { } fn get_reset_pwd(&self) -> std::path::PathBuf { - self.phase_overrides(&self.reset).resolve_pwd(&self.phase_defaults) + self.phase_overrides(&self.reset) + .resolve_pwd(&self.phase_defaults) } fn get_reset_env(&self) -> HashMap { - self.phase_overrides(&self.reset).resolve_env(&self.phase_defaults) + self.phase_overrides(&self.reset) + .resolve_env(&self.phase_defaults) } fn get_reset_timeout_absolute(&self) -> Option { - self.phase_overrides(&self.reset).resolve_timeout_absolute(&self.phase_defaults) + self.phase_overrides(&self.reset) + .resolve_timeout_absolute(&self.phase_defaults) } fn get_reset_timeout_relative(&self) -> Option { - self.phase_overrides(&self.reset).resolve_timeout_relative(&self.phase_defaults) + self.phase_overrides(&self.reset) + .resolve_timeout_relative(&self.phase_defaults) } fn get_langs(&self) -> impl Iterator { diff --git a/crates/bough-cli/src/render.rs b/crates/bough-cli/src/render.rs index c6f11f04..396b1db8 100644 --- a/crates/bough-cli/src/render.rs +++ b/crates/bough-cli/src/render.rs @@ -168,7 +168,8 @@ fn fmt_mutation_markdown_row(m: &Mutation) -> String { ) } -const MARKDOWN_TABLE_HEADER: &str = "| Hash | File | Lang | Kind | Span | Subst |\n| --- | --- | --- | --- | --- | --- |"; +const MARKDOWN_TABLE_HEADER: &str = + "| Hash | File | Lang | Kind | Span | Subst |\n| --- | --- | --- | --- | --- | --- |"; fn fmt_mutation_markdown_table(mutations: &[Mutation]) -> String { let rows: Vec<_> = mutations.iter().map(fmt_mutation_markdown_row).collect(); @@ -218,11 +219,19 @@ impl Render for AllMutations { } fn terse(&self) -> String { - self.0.iter().map(fmt_mutation_terse).collect::>().join("\n") + self.0 + .iter() + .map(fmt_mutation_terse) + .collect::>() + .join("\n") } fn verbose(&self) -> String { - self.0.iter().map(fmt_mutation_verbose).collect::>().join("\n") + self.0 + .iter() + .map(fmt_mutation_verbose) + .collect::>() + .join("\n") } fn json(&self) -> String { @@ -243,11 +252,19 @@ impl Render for LangMutations { } fn terse(&self) -> String { - self.1.iter().map(fmt_mutation_terse).collect::>().join("\n") + self.1 + .iter() + .map(fmt_mutation_terse) + .collect::>() + .join("\n") } fn verbose(&self) -> String { - self.1.iter().map(fmt_mutation_verbose).collect::>().join("\n") + self.1 + .iter() + .map(fmt_mutation_verbose) + .collect::>() + .join("\n") } fn json(&self) -> String { @@ -268,11 +285,19 @@ impl Render for FileMutations { } fn terse(&self) -> String { - self.2.iter().map(fmt_mutation_terse).collect::>().join("\n") + self.2 + .iter() + .map(fmt_mutation_terse) + .collect::>() + .join("\n") } fn verbose(&self) -> String { - self.2.iter().map(fmt_mutation_verbose).collect::>().join("\n") + self.2 + .iter() + .map(fmt_mutation_verbose) + .collect::>() + .join("\n") } fn json(&self) -> String { @@ -342,14 +367,20 @@ impl Render for SingleMutation { m.subst(), status, at, - tag, self.before, - tag, self.after, + tag, + self.before, + tag, + self.after, ) } fn terse(&self) -> String { let m = self.state.mutation(); - format!("{} {}", fmt_mutation_terse(m), fmt_status_from_state(&self.state)) + format!( + "{} {}", + fmt_mutation_terse(m), + fmt_status_from_state(&self.state) + ) } fn verbose(&self) -> String { @@ -358,7 +389,11 @@ impl Render for SingleMutation { let at = fmt_outcome_at_from_state(&self.state); format!( "{}\nStatus: {} ({})\n\n--- before ---\n{}\n\n--- after ---\n{}", - fmt_mutation_verbose(m), status, at, self.before, self.after, + fmt_mutation_verbose(m), + status, + at, + self.before, + self.after, ) } @@ -426,7 +461,10 @@ impl Render for TendWorkspaces { .map(|id| format!("- `{id}`")) .collect::>() .join("\n"); - format!("# Tend Workspaces\n\n{} total\n\n{list}", self.workspace_ids.len()) + format!( + "# Tend Workspaces\n\n{} total\n\n{list}", + self.workspace_ids.len() + ) } fn terse(&self) -> String { @@ -451,7 +489,11 @@ impl Render for TendWorkspaces { } fn json(&self) -> String { - let items: Vec = self.workspace_ids.iter().map(|id| format!("\"{id}\"")).collect(); + let items: Vec = self + .workspace_ids + .iter() + .map(|id| format!("\"{id}\"")) + .collect(); format!("[{}]", items.join(",")) } } @@ -466,7 +508,11 @@ fn fmt_phase_outcome_terse(outcome: &bough_core::PhaseOutcome) -> String { "exit={} duration={:.2}s{}", outcome.exit_code(), outcome.duration().as_secs_f64(), - if outcome.timed_out() { " TIMED_OUT" } else { "" }, + if outcome.timed_out() { + " TIMED_OUT" + } else { + "" + }, ) } @@ -496,8 +542,14 @@ fn fmt_phase_outcome_json(outcome: &bough_core::PhaseOutcome) -> String { outcome.exit_code(), outcome.duration().as_secs_f64(), outcome.timed_out(), - stdout.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n"), - stderr.replace('\\', "\\\\").replace('"', "\\\"").replace('\n', "\\n"), + stdout + .replace('\\', "\\\\") + .replace('"', "\\\"") + .replace('\n', "\\n"), + stderr + .replace('\\', "\\\\") + .replace('"', "\\\"") + .replace('\n', "\\n"), ) } diff --git a/crates/bough-core/src/base.rs b/crates/bough-core/src/base.rs index bac689e3..abd4f433 100644 --- a/crates/bough-core/src/base.rs +++ b/crates/bough-core/src/base.rs @@ -91,7 +91,9 @@ impl Base { config: &impl crate::session::Config, reference_duration: Option, ) -> Result { - let cmd = config.get_init_cmd().ok_or(crate::phase::Error::NoCmdConfigured)?; + let cmd = config + .get_init_cmd() + .ok_or(crate::phase::Error::NoCmdConfigured)?; crate::phase::run_phase( self, &cmd, @@ -108,7 +110,9 @@ impl Base { config: &impl crate::session::Config, reference_duration: Option, ) -> Result { - let cmd = config.get_reset_cmd().ok_or(crate::phase::Error::NoCmdConfigured)?; + let cmd = config + .get_reset_cmd() + .ok_or(crate::phase::Error::NoCmdConfigured)?; crate::phase::run_phase( self, &cmd, diff --git a/crates/bough-core/src/facet_disk_store.rs b/crates/bough-core/src/facet_disk_store.rs index 4e7dba61..e62c7542 100644 --- a/crates/bough-core/src/facet_disk_store.rs +++ b/crates/bough-core/src/facet_disk_store.rs @@ -278,7 +278,11 @@ mod tests { std::fs::write(dir.path().join("good.json"), r#"{"data":"x","count":1}"#).unwrap(); std::fs::write(dir.path().join("no_extension"), "garbage").unwrap(); std::fs::write(dir.path().join("wrong.txt"), "garbage").unwrap(); - std::fs::write(dir.path().join("also_good.json"), r#"{"data":"y","count":2}"#).unwrap(); + std::fs::write( + dir.path().join("also_good.json"), + r#"{"data":"y","count":2}"#, + ) + .unwrap(); let store: FacetDiskStore = FacetDiskStore::new(dir.path().to_path_buf()); let mut keys: Vec<_> = store.keys().map(|k| k.0).collect(); keys.sort(); @@ -311,8 +315,7 @@ mod tests { let val_json = r#"{"data":"preexisting","count":5}"#; std::fs::write(dir.path().join("old.json"), val_json).unwrap(); - let store: FacetDiskStore = - FacetDiskStore::new(dir.path().to_path_buf()); + let store: FacetDiskStore = FacetDiskStore::new(dir.path().to_path_buf()); let got = store.get(&TestKey("old".into())).unwrap(); assert_eq!(got.data, "preexisting"); diff --git a/crates/bough-core/src/lib.rs b/crates/bough-core/src/lib.rs index 28562713..d306c0c8 100644 --- a/crates/bough-core/src/lib.rs +++ b/crates/bough-core/src/lib.rs @@ -37,8 +37,8 @@ pub enum LanguageId { pub use file::File; pub use mutation::Mutation; pub use mutation::MutationHash; +pub use phase::PhaseOutcome; pub use session::Config; pub use session::Session; pub use state::{State, Status}; -pub use phase::PhaseOutcome; pub use workspace::{Workspace, WorkspaceId}; diff --git a/crates/bough-core/src/mutant.rs b/crates/bough-core/src/mutant.rs index 956e8860..0c2dd630 100644 --- a/crates/bough-core/src/mutant.rs +++ b/crates/bough-core/src/mutant.rs @@ -395,7 +395,12 @@ impl<'a, 't> Iterator for TwigMutantsIter<'a, 't> { trace!(?kind, "skipping mutant by query filter"); continue; } - trace!(?kind, start = span.start().byte(), end = span.end().byte(), "found mutant"); + trace!( + ?kind, + start = span.start().byte(), + end = span.end().byte(), + "found mutant" + ); let mutant = Mutant::new(self.lang, self.twig.clone(), kind, span); return Some(BasedMutant::new(mutant, self.base)); } @@ -680,7 +685,10 @@ mod tests { .filter(|m| matches!(m.kind(), MutantKind::BinaryOp(BinaryOpMutationKind::Add))) .collect(); assert_eq!(adds.len(), 1); - assert_eq!(*adds[0].span(), Span::new(Point::new(0, 12, 12), Point::new(0, 13, 13))); + assert_eq!( + *adds[0].span(), + Span::new(Point::new(0, 12, 12), Point::new(0, 13, 13)) + ); } // bough[verify mutant.twig-iter.find.js.binary.sub] @@ -698,7 +706,10 @@ mod tests { .filter(|m| matches!(m.kind(), MutantKind::BinaryOp(BinaryOpMutationKind::Sub))) .collect(); assert_eq!(subs.len(), 1); - assert_eq!(*subs[0].span(), Span::new(Point::new(0, 12, 12), Point::new(0, 13, 13))); + assert_eq!( + *subs[0].span(), + Span::new(Point::new(0, 12, 12), Point::new(0, 13, 13)) + ); } // bough[verify mutant.twig-iter.find.js.binary.add] @@ -1065,7 +1076,10 @@ function sub(a, b) { let (_dir, base) = make_context_base(); let mutant = find_add_mutant(&base); let (text, span) = mutant.get_contextual_fragment(&base, 100).unwrap(); - assert_eq!(text, "function add(a, b) {\n if (a > 0) {\n return a + b;\n }\n return b;\n}"); + assert_eq!( + text, + "function add(a, b) {\n if (a > 0) {\n return a + b;\n }\n return b;\n}" + ); assert_eq!(span, Span::new(Point::new(1, 0, 10), Point::new(6, 1, 91))); } @@ -1074,7 +1088,10 @@ function sub(a, b) { let (_dir, base) = make_context_base(); let mutant = find_add_mutant(&base); let (text, span) = mutant.get_contextual_fragment(&base, 3).unwrap(); - assert_eq!(text, "function add(a, b) {\n if (a > 0) {\n return a + b;\n }\n return b;\n}"); + assert_eq!( + text, + "function add(a, b) {\n if (a > 0) {\n return a + b;\n }\n return b;\n}" + ); assert_eq!(span, Span::new(Point::new(1, 0, 10), Point::new(6, 1, 91))); } @@ -1089,10 +1106,15 @@ function sub(a, b) { #[test] fn contextual_fragment_mutant_at_end_of_function() { - let (_dir, base) = make_js_base("function bar() {\n const x = 1;\n const y = 2;\n return x + y;\n}"); + let (_dir, base) = make_js_base( + "function bar() {\n const x = 1;\n const y = 2;\n return x + y;\n}", + ); let mutant = find_add_mutant(&base); let (text, span) = mutant.get_contextual_fragment(&base, 100).unwrap(); - assert_eq!(text, "function bar() {\n const x = 1;\n const y = 2;\n return x + y;\n}"); + assert_eq!( + text, + "function bar() {\n const x = 1;\n const y = 2;\n return x + y;\n}" + ); assert_eq!(span, Span::new(Point::new(0, 0, 0), Point::new(4, 1, 70))); } } diff --git a/crates/bough-core/src/mutation.rs b/crates/bough-core/src/mutation.rs index 5f095430..d2f9e9f0 100644 --- a/crates/bough-core/src/mutation.rs +++ b/crates/bough-core/src/mutation.rs @@ -376,7 +376,10 @@ mod tests { MutantKind::BinaryOp(BinaryOpMutationKind::Add), Span::new(Point::new(0, 9, 9), Point::new(0, 10, 10)), ); - let mutation = Mutation { mutant, subst: "-".into() }; + let mutation = Mutation { + mutant, + subst: "-".into(), + }; assert_eq!(mutation.apply_to_complete_src_string(src), "return a - b;"); } @@ -390,8 +393,14 @@ mod tests { MutantKind::BinaryOp(BinaryOpMutationKind::Add), Span::new(Point::new(1, 13, 28), Point::new(1, 14, 29)), ); - let mutation = Mutation { mutant, subst: "*".into() }; - assert_eq!(mutation.apply_to_complete_src_string(src), "function f() {\n return a * b;\n}"); + let mutation = Mutation { + mutant, + subst: "*".into(), + }; + assert_eq!( + mutation.apply_to_complete_src_string(src), + "function f() {\n return a * b;\n}" + ); } #[test] @@ -404,7 +413,10 @@ mod tests { MutantKind::StatementBlock, Span::new(Point::new(0, 7, 7), Point::new(0, 17, 17)), ); - let mutation = Mutation { mutant, subst: "{}".into() }; + let mutation = Mutation { + mutant, + subst: "{}".into(), + }; assert_eq!(mutation.apply_to_complete_src_string(src), "if (x) {}"); } @@ -418,7 +430,13 @@ mod tests { MutantKind::Condition, Span::new(Point::new(0, 4, 4), Point::new(0, 9, 9)), ); - let mutation = Mutation { mutant, subst: "true".into() }; - assert_eq!(mutation.apply_to_complete_src_string(src), "if (true) { return 1; }"); + let mutation = Mutation { + mutant, + subst: "true".into(), + }; + assert_eq!( + mutation.apply_to_complete_src_string(src), + "if (true) { return 1; }" + ); } } diff --git a/crates/bough-core/src/session.rs b/crates/bough-core/src/session.rs index b67974e5..8446a94c 100644 --- a/crates/bough-core/src/session.rs +++ b/crates/bough-core/src/session.rs @@ -235,7 +235,6 @@ impl Session { let workspaces_dir = self.config.get_bough_state_dir().join("workspaces"); Workspace::bind_dirty(workspaces_dir, workspace_id, &self.base) } - } impl From for Error { diff --git a/crates/bough-core/src/twig.rs b/crates/bough-core/src/twig.rs index b36ccf44..d607bb1b 100644 --- a/crates/bough-core/src/twig.rs +++ b/crates/bough-core/src/twig.rs @@ -63,10 +63,7 @@ impl TwigsIterBuilder { // bough[impl twig.iter.include.empty] if self.include.is_empty() { - return TwigsIter { - root, - walker: None, - }; + return TwigsIter { root, walker: None }; } let mut overrides = OverrideBuilder::new(root_path); diff --git a/crates/bough-core/src/workspace.rs b/crates/bough-core/src/workspace.rs index 8fe9913c..94ca876f 100644 --- a/crates/bough-core/src/workspace.rs +++ b/crates/bough-core/src/workspace.rs @@ -281,7 +281,9 @@ impl Workspace<'_> { config: &impl crate::session::Config, reference_duration: Option, ) -> Result { - let cmd = config.get_init_cmd().ok_or(crate::phase::Error::NoCmdConfigured)?; + let cmd = config + .get_init_cmd() + .ok_or(crate::phase::Error::NoCmdConfigured)?; crate::phase::run_phase( self, &cmd, @@ -298,7 +300,9 @@ impl Workspace<'_> { config: &impl crate::session::Config, reference_duration: Option, ) -> Result { - let cmd = config.get_reset_cmd().ok_or(crate::phase::Error::NoCmdConfigured)?; + let cmd = config + .get_reset_cmd() + .ok_or(crate::phase::Error::NoCmdConfigured)?; crate::phase::run_phase( self, &cmd, diff --git a/crates/bough-typed-hash/src/lib.rs b/crates/bough-typed-hash/src/lib.rs index 91bc602e..77e3d9c9 100644 --- a/crates/bough-typed-hash/src/lib.rs +++ b/crates/bough-typed-hash/src/lib.rs @@ -55,8 +55,6 @@ pub trait TypedHash: Sized { fn from_raw(bytes: [u8; 32]) -> Self; fn as_bytes(&self) -> &[u8; 32]; - - } /// Data that produces a [`TypedHash`]. @@ -89,8 +87,7 @@ pub fn hex_to_bytes(hex: &str) -> Result<[u8; 32], String> { } let mut bytes = [0u8; 32]; for i in 0..32 { - bytes[i] = u8::from_str_radix(&hex[i * 2..i * 2 + 2], 16) - .map_err(|e| e.to_string())?; + bytes[i] = u8::from_str_radix(&hex[i * 2..i * 2 + 2], 16).map_err(|e| e.to_string())?; } Ok(bytes) } diff --git a/crates/bough-typed-hash/src/tests.rs b/crates/bough-typed-hash/src/tests.rs index 50212838..37ada481 100644 --- a/crates/bough-typed-hash/src/tests.rs +++ b/crates/bough-typed-hash/src/tests.rs @@ -75,30 +75,63 @@ fn typed_hash_display_format() { #[test] fn typed_hashable_produces_hash() { - let w = Widget { name: "gear".into(), count: 5 }; + let w = Widget { + name: "gear".into(), + count: 5, + }; let h = w.hash().unwrap(); assert_eq!(h.to_string().len(), 64); } #[test] fn typed_hashable_deterministic() { - let a = Widget { name: "gear".into(), count: 5 }; - let b = Widget { name: "gear".into(), count: 5 }; + let a = Widget { + name: "gear".into(), + count: 5, + }; + let b = Widget { + name: "gear".into(), + count: 5, + }; assert_eq!(a.hash().unwrap(), b.hash().unwrap()); } #[test] fn typed_hashable_different_values_differ() { - let a = Widget { name: "gear".into(), count: 5 }; - let b = Widget { name: "gear".into(), count: 6 }; + let a = Widget { + name: "gear".into(), + count: 5, + }; + let b = Widget { + name: "gear".into(), + count: 6, + }; assert_ne!(a.hash().unwrap(), b.hash().unwrap()); } #[test] fn hash_into_derive_nested() { - let a = Assembly { part: Part { label: "bolt".into(), weight: 1.5 }, quantity: 10 }; - let b = Assembly { part: Part { label: "bolt".into(), weight: 1.5 }, quantity: 10 }; - let c = Assembly { part: Part { label: "nut".into(), weight: 0.5 }, quantity: 10 }; + let a = Assembly { + part: Part { + label: "bolt".into(), + weight: 1.5, + }, + quantity: 10, + }; + let b = Assembly { + part: Part { + label: "bolt".into(), + weight: 1.5, + }, + quantity: 10, + }; + let c = Assembly { + part: Part { + label: "nut".into(), + weight: 0.5, + }, + quantity: 10, + }; assert_eq!(a.hash().unwrap(), b.hash().unwrap()); assert_ne!(a.hash().unwrap(), c.hash().unwrap()); } @@ -108,7 +141,10 @@ fn hash_into_derive_enum() { #[derive(HashInto)] enum Shape { Circle(f64), - Rect { w: f64, h: f64 }, + Rect { + w: f64, + h: f64, + }, #[allow(dead_code)] Point, } @@ -128,7 +164,10 @@ fn hash_into_derive_enum() { #[test] fn unvalidated_hash_full_hex() { - let w = Widget { name: "q".into(), count: 7 }; + let w = Widget { + name: "q".into(), + count: 7, + }; let h = w.hash().unwrap(); let hex = h.to_string(); @@ -139,7 +178,10 @@ fn unvalidated_hash_full_hex() { #[test] fn unvalidated_hash_prefix() { - let w = Widget { name: "y".into(), count: 2 }; + let w = Widget { + name: "y".into(), + count: 2, + }; let h = w.hash().unwrap(); let hex = h.to_string(); @@ -231,12 +273,25 @@ fn vec_order_matters() { #[test] fn string_length_prefix_prevents_collisions() { #[derive(HashInto)] - struct Pair { a: String, b: String } + struct Pair { + a: String, + b: String, + } let mut s1 = Sha256::new(); let mut s2 = Sha256::new(); - Pair { a: "ab".into(), b: "c".into() }.hash_into(&mut s1).unwrap(); - Pair { a: "a".into(), b: "bc".into() }.hash_into(&mut s2).unwrap(); + Pair { + a: "ab".into(), + b: "c".into(), + } + .hash_into(&mut s1) + .unwrap(); + Pair { + a: "a".into(), + b: "bc".into(), + } + .hash_into(&mut s2) + .unwrap(); assert_ne!( <[u8; 32]>::from(s1.finalize()), <[u8; 32]>::from(s2.finalize()), diff --git a/crates/bough-typed-hash/src/unvalidated.rs b/crates/bough-typed-hash/src/unvalidated.rs index 864ed4f8..8386a061 100644 --- a/crates/bough-typed-hash/src/unvalidated.rs +++ b/crates/bough-typed-hash/src/unvalidated.rs @@ -33,10 +33,7 @@ impl UnvalidatedHash { } /// Validate against a set of known hashes, supporting both full hex and unique prefixes. - pub fn validate( - self, - known: &[H], - ) -> Result> { + pub fn validate(self, known: &[H]) -> Result> { debug!(hex_len = self.0.len(), "validating unvalidated hash"); let s = &self.0; -- knotmirror 0.0.1