d10p2 trying question mark
This commit is contained in:
		| @@ -1,3 +1,4 @@ | ||||
| use std::num; | ||||
| use std::env; | ||||
| use std::process; | ||||
| use std::fs::File; | ||||
| @@ -11,14 +12,16 @@ enum Inst{ | ||||
|  | ||||
| #[derive(Debug)] | ||||
| struct ParseError(String); | ||||
| impl From<num::ParseIntError> for ParseError { | ||||
|     fn from(e: num::ParseIntError) -> Self { | ||||
|         ParseError(e.to_string()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn parse_line(line: String) -> Result<Inst, ParseError> { | ||||
|     match &line[..4] { | ||||
|         "noop" => Ok(Inst::Noop), | ||||
|         "addx" => match line[5..].parse::<i64>() { | ||||
|             Ok(operand) => Ok(Inst::AddX(operand)), | ||||
|             Err(e) => Err(ParseError(e.to_string())), | ||||
|         }, | ||||
|         "addx" => Ok(Inst::AddX(line[5..].parse::<i64>()?)), | ||||
|         _ => Err(ParseError(String::from("bad instruction"))), | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user