From e60ca57bc75eb6cf3e94f51fd0e05c9d444af2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rativel?= Date: Wed, 8 Mar 2023 13:04:03 +0100 Subject: [PATCH] Warning fix --- src/simulator/mem_cmp.rs | 47 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index febe371..7e7e8f5 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -1,5 +1,4 @@ use std::fs; -use std::io; use std::io::BufRead; use std::io::BufReader; use std::io::Lines; @@ -70,11 +69,11 @@ impl Section{ } } - Section{addr:addr, len:len, content:content} + Section{addr, len, content} } - fn print_Section(s: &Section){ + fn print_section(s: &Section){ println!("ADDR :: {:x}", s.addr); println!("LEN :: {:x}", s.len); println!("CONTENT :: {:?}", s.content); @@ -84,14 +83,14 @@ impl Section{ /* * Representation de l'etat de la mémoire (apres execution.... a confirmer), sous forme de sections */ -pub struct Mem_Checker{ +pub struct MemChecker{ pc: usize, sp: usize, sections: Vec
, } -impl Mem_Checker{ +impl MemChecker{ ///Translate lines of a file in e Vector of String ///We need this method to parse the memory we received @@ -104,7 +103,7 @@ impl Mem_Checker{ /// - A vector of String where each line of the file os an element of the vector fn vect_from_lines(lines: &mut Lines>, pc: &mut usize, sp: &mut usize) -> Vec{ let mut vector = Vec::new(); - for (i,line) in lines.enumerate() { + for (_,line) in lines.enumerate() { vector.push(line.unwrap()); } let size = vector.len(); @@ -121,16 +120,16 @@ impl Mem_Checker{ /// /// ### Return /// Mem-checker filled - pub fn from(path: &String) -> Mem_Checker { + pub fn from(path: &String) -> MemChecker { let file = fs::File::open(path).expect("Wrong filename"); - let reader = io::BufReader::new(file); + let reader = BufReader::new(file); let mut lines = reader.lines(); let mut pc: usize = 0; let mut sp: usize = 0; - let vector = Mem_Checker::vect_from_lines(&mut lines, &mut pc, &mut sp); + let vector = MemChecker::vect_from_lines(&mut lines, &mut pc, &mut sp); let mut sections: Vec
= Vec::new(); let mut tmp_addr_str: String = String::new(); @@ -159,7 +158,7 @@ impl Mem_Checker{ } - Mem_Checker{pc:pc, sp:sp, sections:sections} + MemChecker{pc, sp, sections} } @@ -168,13 +167,13 @@ impl Mem_Checker{ /// ### Parameter /// /// - **m_c** Contains the data we want to print - pub fn print_Mem_Checker(m_c: &Mem_Checker){ + pub fn print_mem_checker(m_c: &MemChecker){ println!("PC :: {:x}", m_c.pc); println!("SP :: {:x}", m_c.sp); for(i,s) in m_c.sections.iter().enumerate() { println!("\nSection {}\n", i); - Section::print_Section(&s); + Section::print_section(&s); } } @@ -185,7 +184,7 @@ impl Mem_Checker{ /// /// - **m_c** contains the data /// - **machine** contains the memry to fill - pub fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){ + pub fn fill_memory_from_mem_checker(m_c: &MemChecker, machine: &mut Machine){ machine.sp = m_c.sp; machine.int_reg.set_reg(2, m_c.pc as i64); @@ -204,9 +203,9 @@ impl Mem_Checker{ /* * FOR DEBUG */ - fn compare_print_m_c_machine(m_c: &Mem_Checker, machine: &mut Machine){ + fn compare_print_m_c_machine(m_c: &MemChecker, machine: &mut Machine){ - Mem_Checker::print_Mem_Checker(m_c); + MemChecker::print_mem_checker(m_c); for section in m_c.sections.iter() { @@ -222,7 +221,7 @@ impl Mem_Checker{ } - pub fn compare_machine_memory(m_c: &Mem_Checker, machine: &Machine) -> bool { + pub fn compare_machine_memory(m_c: &MemChecker, machine: &Machine) -> bool { for section in m_c.sections.iter() { for i in 0..section.len { @@ -252,7 +251,7 @@ fn string_hex_to_usize(s: &String) -> usize { for (i,c )in s.chars().enumerate(){ //println!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32)); - let tmp: usize = (one_hex_to_dec(c) as usize); + let tmp: usize = one_hex_to_dec(c) as usize; ret_value += base.pow(max_pow - (i as u32))*tmp; } @@ -297,7 +296,7 @@ fn two_hex_to_u8(c1: char, c2: char) -> u8 { */ fn test_show_sections_file(){ let file = fs::File::open("test_file_section.txt").expect("Wrong filename"); - let reader = io::BufReader::new(file); + let reader = BufReader::new(file); for line in reader.lines() { //println!("Tailles de la ligne : {}", @@ -318,14 +317,14 @@ mod tests { #[test] fn test_fill_memory(){ let path = "osef".to_string(); - let m_c = Mem_Checker::from(&path); + let m_c = MemChecker::from(&path); let mut machine = Machine::_init_machine(); - Mem_Checker::fill_memory_from_Mem_Checker(&m_c, &mut machine); + MemChecker::fill_memory_from_mem_checker(&m_c, &mut machine); print!("\n Comparing memory from loaded context\n\n"); - Mem_Checker::compare_print_m_c_machine(&m_c, &mut machine); + MemChecker::compare_print_m_c_machine(&m_c, &mut machine); } @@ -339,10 +338,10 @@ mod tests { } #[test] - fn test_create_Mem_Checker(){ + fn test_create_mem_checker(){ let path: String = "osef".to_string(); - let m_c = Mem_Checker::from(&path); - Mem_Checker::print_Mem_Checker(&m_c); + let m_c = MemChecker::from(&path); + MemChecker::print_mem_checker(&m_c); }