fn parse(all_text : String) -> Vec<Node> {

	//Find the relevant section. We want the data after "NODE_COORD_SECTION"
	let mut split_point = all_text.find("NODE_COORD_SECTION");

	//Relevant section does not exist.
	if split_point == None {
		println!("ERROR: Input file has invalid syntax. No NODE_COORD_SECTION.");
		exit(0);
	}

	//Dump the data before "NODE_COORD_SECTION". Our data is in all_text
	let (trash, all_text) = all_text.split_at(split_point.unwrap());
	drop(trash);

	//"NODE_COORD_SECTION" is included in all_text so split at the first \n
	split_point = all_text.find("\n");

	//No data
	if split_point == None {
		println!("ERROR: Input file has invalid syntax. No data after NODE_COORD_SECTION");
		exit(0);
	}

	//Dump "NODE_COORD_SECTION\n"
	let (trash, all_text) = all_text.split_at(split_point.unwrap()+1);
	drop(trash);

	//.tsp files contain a literal "EOF"
	split_point = all_text.find("EOF");

	//"EOF" not found
	if split_point == None {
		println!("ERROR: Input file has invalid syntax. No explicit (literal) EOF.");
		exit(0);
	}

	//Dump all the data after "EOF"
	let (all_text, trash) = all_text.split_at(split_point.unwrap()-1);
	drop(trash);


	//Now have list of nodes, in the format "[id] [x] [y]" with one node per line.


	let nodes_iterator = all_text.lines();
	//An array of Nodes
	let mut path : Vec<Node> = Vec::new();

	//Parsing has no error handling. If the data is in an invalid format, the function will fail.
	//Iterate over each line in all_text, and parse the data into Node objects
	for each_node in nodes_iterator {
		//An iterator split by whitespace
		let mut coords_iterator = each_node.split_whitespace();
		//First num will be id
		let id = coords_iterator.next().unwrap().parse::<i32>().unwrap();
		//Second num will be x coordinate
		let x = coords_iterator.next().unwrap().parse::<i32>().unwrap();
		//Third num will be y coordinate
		let y = coords_iterator.next().unwrap().parse::<i32>().unwrap();
		//That should be the end of this line.

		let new_node = Node {id:id, x:x, y:y};
		path.push(new_node);
	}

	path
}
//Parse the input file into a Vec<Node>
Parse the input file into a Vec
Parse the input file into a Vec
fn parse(all_text : String) -> Vec<Node> {
	//Find the relevant section. We want the data after "NODE_COORD_SECTION"
	let mut split_point = all_text.find("NODE_COORD_SECTION");
	//Relevant section does not exist.
	if split_point == None {
		println!("ERROR: Input file has invalid syntax. No NODE_COORD_SECTION.");
		exit(0);
	}
	//Dump the data before "NODE_COORD_SECTION". Our data is in all_text
	let (trash, all_text) = all_text.split_at(split_point.unwrap());
	drop(trash);
	//"NODE_COORD_SECTION" is included in all_text so split at the first \n
	split_point = all_text.find("\n");
	//No data
	if split_point == None {
		println!("ERROR: Input file has invalid syntax. No data after NODE_COORD_SECTION");
		exit(0);
	}
	//Dump "NODE_COORD_SECTION\n"
	let (trash, all_text) = all_text.split_at(split_point.unwrap()+1);
	drop(trash);
	//.tsp files contain a literal "EOF"
	split_point = all_text.find("EOF");
	//"EOF" not found
	if split_point == None {
		println!("ERROR: Input file has invalid syntax. No explicit (literal) EOF.");
		exit(0);
	}
	//Dump all the data after "EOF"
	let (all_text, trash) = all_text.split_at(split_point.unwrap()-1);
	drop(trash);
	//Now have list of nodes, in the format "[id] [x] [y]" with one node per line.
	let nodes_iterator = all_text.lines();
	//An array of Nodes
	let mut path : Vec<Node> = Vec::new();
	//Parsing has no error handling. If the data is in an invalid format, the function will fail.
	//Iterate over each line in all_text, and parse the data into Node objects
	for each_node in nodes_iterator {
		//An iterator split by whitespace
		let mut coords_iterator = each_node.split_whitespace();
		//First num will be id
		let id = coords_iterator.next().unwrap().parse::<i32>().unwrap();
		//Second num will be x coordinate
		let x = coords_iterator.next().unwrap().parse::<i32>().unwrap();
		//Third num will be y coordinate
		let y = coords_iterator.next().unwrap().parse::<i32>().unwrap();
		//That should be the end of this line.
		let new_node = Node {id:id, x:x, y:y};
		path.push(new_node);
	}
	path
}
fn parse ( all_text : String ) -> Vec < Node > { //Find the relevant section. We want the data after "NODE_COORD_SECTION" let mut split_point = all_text . find ( " " ) ; //Relevant section does not exist. if split_point == None { println ! ( " " ) ; exit ( 0 ) ; } //Dump the data before "NODE_COORD_SECTION". Our data is in all_text let ( trash , all_text ) = all_text . split_at ( split_point . unwrap ( ) ) ; drop ( trash ) ; //"NODE_COORD_SECTION" is included in all_text so split at the first \n split_point = all_text . find ( " \n " ) ; //No data if split_point == None { println ! ( " " ) ; exit ( 0 ) ; } //Dump "NODE_COORD_SECTION\n" let ( trash , all_text ) = all_text . split_at ( split_point . unwrap ( ) + 1 ) ; drop ( trash ) ; //.tsp files contain a literal "EOF" split_point = all_text . find ( " " ) ; //"EOF" not found if split_point == None { println ! ( " " ) ; exit ( 0 ) ; } //Dump all the data after "EOF" let ( all_text , trash ) = all_text . split_at ( split_point . unwrap ( ) - 1 ) ; drop ( trash ) ; //Now have list of nodes, in the format "[id] [x] [y]" with one node per line. let nodes_iterator = all_text . lines ( ) ; //An array of Nodes let mut path : Vec < Node > = Vec :: new ( ) ; //Parsing has no error handling. If the data is in an invalid format, the function will fail. //Iterate over each line in all_text, and parse the data into Node objects for each_node in nodes_iterator { //An iterator split by whitespace let mut coords_iterator = each_node . split_whitespace ( ) ; //First num will be id let id = coords_iterator . next ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) ; //Second num will be x coordinate let x = coords_iterator . next ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) ; //Third num will be y coordinate let y = coords_iterator . next ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) ; //That should be the end of this line. let new_node = Node { id : id , x : x , y : y } ; path . push ( new_node ) ; } path }
Parse the input file into a Vec<Node>
Parse the input file into a Vec<Node >
all_text
String
all_text
String