Prototype of the parsing_config() func
This commit is contained in:
		
							parent
							
								
									555a0ff6b8
								
							
						
					
					
						commit
						430e706831
					
				
							
								
								
									
										11
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.rs
									
									
									
									
									
								
							@ -18,6 +18,16 @@ use std::fs;
 | 
				
			|||||||
use std::io;
 | 
					use std::io;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod robot;
 | 
					mod robot;
 | 
				
			||||||
 | 
					mod world;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Parse the config file, generate the world and robot pool.
 | 
				
			||||||
 | 
					fn parse_config(raw_conf: String, pool: &Vec<robot::Robot>) -> Result<world::World, &'static str> {
 | 
				
			||||||
 | 
					    // test exemple, i am currently writting the real code.
 | 
				
			||||||
 | 
					    // This function return the map OR an error inside a Result so we
 | 
				
			||||||
 | 
					    // can catch error using '?' in main
 | 
				
			||||||
 | 
					    // we also create robots here and put them into the pool.
 | 
				
			||||||
 | 
					    Ok(world::World { x: 5, y: 5 })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Retrieve the content of a file and return it as a string.
 | 
					/// Retrieve the content of a file and return it as a string.
 | 
				
			||||||
fn open_file(filename: &str) -> io::Result<String> {
 | 
					fn open_file(filename: &str) -> io::Result<String> {
 | 
				
			||||||
@ -42,6 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
				
			|||||||
    let raw_conf = open_file(matches.value_of("file").unwrap_or("two_robots.txt"))?;
 | 
					    let raw_conf = open_file(matches.value_of("file").unwrap_or("two_robots.txt"))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let robot_pool: Vec<robot::Robot> = Vec::new();
 | 
					    let robot_pool: Vec<robot::Robot> = Vec::new();
 | 
				
			||||||
 | 
					    let world = parse_config(raw_conf, &robot_pool)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ok(())
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user