~vam-jam/wpath

44b3bccc0151bf08f99f8c3ccd45c223a0a6bd65 — Vamist 1 year, 7 months ago 9c0bac8
[dev] Small cleanup
1 files changed, 23 insertions(+), 25 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +23 -25
@@ 1,8 1,11 @@
use core::fmt;
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, Error, ErrorKind};
use std::{env, path::PathBuf, process::exit};
use std::{
    env, io,
    io::{BufRead, BufReader},
    path::PathBuf,
};

#[derive(Debug, PartialEq, Eq)]
struct WordPath {


@@ 66,10 69,10 @@ impl Step {
}

impl WordPath {
    fn read(&mut self) -> Result<Vec<String>, Error> {
    fn read(&mut self) -> Result<Vec<String>, io::Error> {
        if !self.file.exists() {
            return Err(Error::new(
                ErrorKind::NotFound,
            return Err(io::Error::new(
                io::ErrorKind::NotFound,
                format!("File {} could not be found", self.file.display()),
            ));
        }


@@ 77,27 80,21 @@ impl WordPath {
        let file = File::open(&mut self.file)?;
        let content = BufReader::new(file).lines();

        let content: Result<Vec<String>, Error> = content.collect();
        let content: Result<Vec<String>, io::Error> = content.collect();
        let content = content?;

        Ok(content)
    }

    fn run(&mut self) -> Result<Solution, Error> {
        let words = self.read()?;
    fn run(&mut self) -> Result<Solution, String> {
        let words = self.read();

        let solution = self.solve(&words);

        if let Err(why) = solution {
            println!("{}", why);
            exit(1);
        if let Err(why) = words {
            return Err(why.to_string());
        }

        let solution = solution.unwrap();

        println!("{}", solution);

        todo!();
        let words = words.unwrap();
        self.solve(&words)
    }

    fn solve(&self, words: &[String]) -> Result<Solution, String> {


@@ 148,10 145,6 @@ impl WordPath {
                            *searched = true;
                            next_search.push(step.branch(word));
                        }

                        // words.get_mut(&word).unwrap().push(lead.clone());

                        // next_search.push(word.clone());
                    }
                }
            }


@@ 171,13 164,18 @@ fn main() {
    let wordpath = fetch_args();

    if let Err(why) = wordpath {
        println!("{why}");
        exit(1);
        panic!("{why}");
    }

    let mut wordpath = wordpath.unwrap();

    wordpath.run();
    let result = wordpath.run();

    if let Err(why) = result {
        panic!("{why}");
    }

    println!("{}", result.unwrap());
}

fn fetch_args() -> Result<WordPath, String> {