Skip to content

Commit 61fdb10

Browse files
author
Edmo Lima
committed
refactor: update style
1 parent 245006a commit 61fdb10

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

src/algorithm/document_distance.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ pub fn document_distance(a: &str, b: &str) -> f64 {
3131

3232
let dot_product: f64 = vec_a.iter().zip(vec_b.iter()).map(|(x, y)| x * y).sum();
3333

34-
let norm = |v: &[f64]| {
35-
v.iter().map(|x| x * x).sum::<f64>().sqrt()
36-
};
34+
let norm = |v: &[f64]| v.iter().map(|x| x * x).sum::<f64>().sqrt();
3735

3836
let norm_a = norm(&vec_a);
3937
let norm_b = norm(&vec_b);
@@ -65,4 +63,4 @@ fn get_word_frequencies(text: &str) -> HashMap<String, f64> {
6563
});
6664

6765
word_counts
68-
}
66+
}

src/cli.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use clap::{Parser, Subcommand};
32

43
/// Docdiff CLI arguments and subcommands
@@ -25,4 +24,3 @@ pub enum Commands {
2524
/// Show information about the program.
2625
Info,
2726
}
28-

src/commands/diff.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
use anyhow::Result;
21
use crate::utils;
3-
use docdiff::algorithm::document_distance;
2+
use anyhow::Result;
43
use colored::*;
4+
use docdiff::algorithm::document_distance;
55

66
pub fn run(original: &str, modified: &str) -> Result<()> {
7-
println!("\n{} Comparing '{}' with '{}'...", "🔍".blue().bold(), original.green(), modified.green());
7+
println!(
8+
"\n{} Comparing '{}' with '{}'...",
9+
"🔍".blue().bold(),
10+
original.green(),
11+
modified.green()
12+
);
813
let text_a = utils::read_file(original)?;
914
let text_b = utils::read_file(modified)?;
1015

@@ -31,7 +36,11 @@ pub fn run(original: &str, modified: &str) -> Result<()> {
3136
};
3237

3338
println!("{}", "Result:".bold().underline());
34-
println!("Document distance: {} (Similarity: {}%)", format!("{:.3}", distance).cyan(), format!("{:.0}", similarity).cyan());
39+
println!(
40+
"Document distance: {} (Similarity: {}%)",
41+
format!("{:.3}", distance).cyan(),
42+
format!("{:.0}", similarity).cyan()
43+
);
3544
println!("{}\n", verdict.color(verdict_color).bold());
3645
Ok(())
3746
}

src/main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
pub mod commands;
21
mod cli;
2+
pub mod commands;
33
mod utils;
44

5+
use crate::cli::{Cli, Commands};
56
use anyhow::Result;
67
use clap::Parser;
7-
use crate::cli::{Cli, Commands};
88

99
fn main() -> Result<()> {
1010
let cli = Cli::parse();
1111
match cli.command {
12-
Commands::Diff { original, modified } => {
13-
commands::diff::run(&original, &modified)
14-
}
12+
Commands::Diff { original, modified } => commands::diff::run(&original, &modified),
1513
Commands::Info => {
1614
commands::info::run();
1715
Ok(())

src/utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use anyhow::{Context, Result};
12
use std::fs;
2-
use anyhow::{Result, Context};
33

44
/// Reads the entire contents of a file as a String.
55
pub fn read_file(path: &str) -> Result<String> {
6-
fs::read_to_string(path)
7-
.with_context(|| format!("Failed to read file: {path}"))
6+
fs::read_to_string(path).with_context(|| format!("Failed to read file: {path}"))
87
}

0 commit comments

Comments
 (0)