From b48664d1e0cf0a52e69d80a3229ef687f67af027 Mon Sep 17 00:00:00 2001 From: Luckas Date: Tue, 9 Apr 2024 22:58:31 +0300 Subject: [PATCH] refactor(cli): additional changes --- three-style-cli/src/main.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/three-style-cli/src/main.rs b/three-style-cli/src/main.rs index 6763ca6..08693f6 100644 --- a/three-style-cli/src/main.rs +++ b/three-style-cli/src/main.rs @@ -34,10 +34,14 @@ impl Cli { depth, }) = self.command { + let allowed_moves = gen + .chars() + .map(|c| MoveKind::from_str(&c.to_string())) + .collect::, _>>()?; let start = Instant::now(); let commutators = match (corners, edges) { - (Some(corners), None) => search_corner_commutators(corners, gen, depth)?, - (None, Some(edges)) => search_edge_commutators(edges, gen, depth)?, + (Some(corners), None) => search_corner_commutators(corners, allowed_moves, depth)?, + (None, Some(edges)) => search_edge_commutators(edges, allowed_moves, depth)?, _ => unreachable!(), }; let end = Instant::now(); @@ -74,7 +78,7 @@ enum Command { fn search_corner_commutators( corners: Vec, - gen: String, + allowed_moves: Vec, depth: u8, ) -> Result, Error> { let corners = corners @@ -82,10 +86,6 @@ fn search_corner_commutators( .map(|c| Corner::from_str(&c)) .collect::, _>>()?; let cycle = Cycle::new(corners[0], corners[1], corners[2]); - let allowed_moves = gen - .chars() - .map(|c| MoveKind::from_str(&c.to_string())) - .collect::, _>>()?; let results = find_corner_commutators(cycle, &allowed_moves, depth); Ok(results) @@ -93,7 +93,7 @@ fn search_corner_commutators( fn search_edge_commutators( edges: Vec, - gen: String, + allowed_moves: Vec, depth: u8, ) -> Result, Error> { let edges = edges @@ -101,10 +101,6 @@ fn search_edge_commutators( .map(|c| Edge::from_str(&c)) .collect::, _>>()?; let cycle = Cycle::new(edges[0], edges[1], edges[2]); - let allowed_moves = gen - .chars() - .map(|c| MoveKind::from_str(&c.to_string())) - .collect::, _>>()?; let results = find_edge_commutators(cycle, &allowed_moves, depth); Ok(results) @@ -137,7 +133,7 @@ fn print_commutators(commutators: Vec, duration: Duration) { } } -fn print_error(error: String) { +fn print_error(error: Error) { let style = Style::new() .bold() .fg_color(Some(Color::Ansi(AnsiColor::Red))); @@ -150,7 +146,7 @@ fn main() { let result = cli.exec(); if let Err(error) = result { - print_error(error.to_string()); + print_error(error); process::exit(1); } }