renamed some vars to be in line with the general naming convention

This commit is contained in:
2022-12-04 20:34:08 +01:00
parent 529098eddf
commit 7386c7c985

View File

@@ -5,7 +5,7 @@ use substring::Substring;
fn main() { fn main() {
let mut elfBuffer: Vec<String> = Vec::new(); let mut elf_buffer: Vec<String> = Vec::new();
let mut value: u64 = 0; let mut value: u64 = 0;
let current_path = std::env::current_dir().unwrap(); let current_path = std::env::current_dir().unwrap();
let res = rfd::FileDialog::new().set_directory(&current_path).pick_file().unwrap(); let res = rfd::FileDialog::new().set_directory(&current_path).pick_file().unwrap();
@@ -13,23 +13,27 @@ fn main() {
let reader = BufReader::new(list); let reader = BufReader::new(list);
for buffer in reader.lines() { for buffer in reader.lines() {
if let Ok(line) = buffer { if let Ok(line) = buffer {
elfBuffer.push(line.clone()); elf_buffer.push(line.clone());
if (elfBuffer.len() == 3) { if (elf_buffer.len() == 3) {
value += parse_elfs(elfBuffer[0].clone(), elfBuffer[1].clone(), elfBuffer[2].clone()); if let Ok(temp_value) = parse_elfs(elf_buffer[0].clone(), elf_buffer[1].clone(), elf_buffer[2].clone()) {
elfBuffer = Vec::new() value += temp_value.clone();
}
else {
println!("Could not find a similarity for lines:\n{}\n{}\n{}\n\n\n", elf_buffer[0], elf_buffer[1], elf_buffer[2])
}
elf_buffer = Vec::new()
} }
} }
} }
println!("{}", value) println!("{}", value)
} }
pub fn parse_elfs(elf_a: String, elf_b: String, elf_c: String) -> u64{ pub fn parse_elfs(elf_a: String, elf_b: String, elf_c: String) -> Result<u64, String> {
for char in elf_a.as_bytes() { for char in elf_a.as_bytes() {
if elf_b.as_bytes().contains(char) && elf_c.as_bytes().contains(char) { if elf_b.as_bytes().contains(char) && elf_c.as_bytes().contains(char) {
return convert_value(char.clone()); return Ok(convert_value(char.clone()));
} }
} }
return 0;//nothing found Err("no similar character found :/".parse().unwrap())
//TODO when nothing found make this throw an err and catch the err above
} }
fn convert_value(value: u8) -> u64 { fn convert_value(value: u8) -> u64 {