assist 0.1.0

assist.org rust analysis
Documentation
use std::collections::HashSet;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

fn main() -> io::Result<()> {
    // Specify the file path
    let path = "txt.log";

    // Open the file
    let file = File::open(&Path::new(path))?;
    let reader = io::BufReader::new(file);

    // Create a HashSet to store the lines
    let mut lines_set: HashSet<String> = HashSet::new();

    // Counter for the total number of lines
    let mut total_lines = 0;

    // Iterate over the lines in the file and insert them into the HashSet
    for line in reader.lines() {
        let line = line?;
        total_lines += 1;
        lines_set.insert(line.trim().to_string());
    }
    let mut lines = lines_set.into_iter().collect::<Vec<String>>();
    lines.sort();
    // Print the contents of the HashSet
    for line in &lines {
        println!("{}", line);
    }

    // Calculate and print the difference between total lines and unique lines
    let unique_lines = lines.len();
    eprintln!("Total lines: {}", total_lines);
    eprintln!("Unique lines: {}", unique_lines);
    eprintln!("Difference: {}", total_lines - unique_lines);

    Ok(())
}