@@ -11,8 +11,8 @@ const_assert!(i128::MAX > 4 * PART2_SHIFT as CalcInt * PART2_SHIFT as CalcInt);
1111
1212pub fn solve ( input : & str ) -> ( usize , usize ) {
1313 let machines = Machine :: parse_all ( input)
14- . filter_map ( |m| m . ok ( ) )
15- . collect :: < Vec < _ > > ( ) ;
14+ . collect :: < Result < Vec < _ > , _ > > ( )
15+ . unwrap ( ) ;
1616
1717 ( part1 ( & machines) , part2 ( & machines) )
1818}
@@ -45,16 +45,6 @@ struct Machine {
4545 b_action : [ StoreInt ; 2 ] ,
4646}
4747
48- #[ derive( Error , Debug ) ]
49- enum MachineParseError {
50- #[ error( "Wrong Format" ) ]
51- WrongNumberFormat ( #[ from] ParseIntError ) ,
52- #[ error( "Wrong Format" ) ]
53- WrongFormat ,
54- #[ error( "Not enough Data" ) ]
55- NotEnoughData ,
56- }
57-
5848impl Machine {
5949 fn solve ( & self ) -> Option < Solution > {
6050 // prize = a_presses * a_action + b_presses * b_action
@@ -86,14 +76,24 @@ impl Machine {
8676 }
8777}
8878
79+ #[ derive( Error , Debug ) ]
80+ enum MachineParseError {
81+ #[ error( "Wrong Format" ) ]
82+ WrongNumberFormat ( #[ from] ParseIntError ) ,
83+ #[ error( "Wrong Format" ) ]
84+ WrongFormat ,
85+ #[ error( "Not enough Data" ) ]
86+ NotEnoughData ,
87+ }
88+
8989impl FromStr for Machine {
9090 type Err = MachineParseError ;
9191
9292 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
9393 fn parse_button ( line : & str , name : & str ) -> Result < ( StoreInt , StoreInt ) , MachineParseError > {
9494 line. strip_prefix ( & format ! ( "Button {}: X+" , name) )
9595 . and_then ( |rest| rest. split_once ( ", Y+" ) )
96- . ok_or ( MachineParseError :: WrongFormat ) // Would want WrongFormat, but then the typechecker gets confused
96+ . ok_or ( MachineParseError :: WrongFormat )
9797 . and_then ( |( x, y) | Ok ( ( x. parse ( ) ?, y. parse ( ) ?) ) )
9898 }
9999
0 commit comments