@@ -112,14 +112,9 @@ impl core::fmt::Debug for TerminalModeError {
112112 }
113113}
114114
115- // Cannot use From<_> due to coherence
116- trait IntoTerminalModeResult < T > {
117- fn terminal_err ( self ) -> Result < T , TerminalModeError > ;
118- }
119-
120- impl < T > IntoTerminalModeResult < T > for Result < T , DisplayError > {
121- fn terminal_err ( self ) -> Result < T , TerminalModeError > {
122- self . map_err ( TerminalModeError :: InterfaceError )
115+ impl From < DisplayError > for TerminalModeError {
116+ fn from ( value : DisplayError ) -> Self {
117+ TerminalModeError :: InterfaceError ( value)
123118 }
124119}
125120
@@ -147,7 +142,7 @@ where
147142 ///
148143 /// This method resets the cursor but does not clear the screen.
149144 fn set_rotation ( & mut self , rot : DisplayRotation ) -> Result < ( ) , TerminalModeError > {
150- self . set_rotation ( rot) . terminal_err ( ) ?;
145+ self . set_rotation ( rot) ?;
151146 // Need to reset cursor position, otherwise coordinates can become invalid
152147 self . reset_pos ( )
153148 }
@@ -156,7 +151,7 @@ where
156151 /// column 0 on the left and column _(SIZE::Width::U8 - 1)_ on the right, but no automatic line
157152 /// wrapping.
158153 fn init ( & mut self ) -> Result < ( ) , TerminalModeError > {
159- self . init_with_addr_mode ( AddrMode :: Page ) . terminal_err ( ) ?;
154+ self . init_with_addr_mode ( AddrMode :: Page ) ?;
160155 self . reset_pos ( ) ?;
161156 Ok ( ( ) )
162157 }
@@ -170,7 +165,7 @@ where
170165 /// Clear the display and reset the cursor to the top left corner
171166 pub fn clear ( & mut self ) -> Result < ( ) , TerminalModeError > {
172167 // Let the chip handle line wrapping so we can fill the screen with blanks faster
173- self . set_addr_mode ( AddrMode :: Horizontal ) . terminal_err ( ) ?;
168+ self . set_addr_mode ( AddrMode :: Horizontal ) ?;
174169
175170 let offset_x = match self . rotation ( ) {
176171 DisplayRotation :: Rotate0 | DisplayRotation :: Rotate270 => SIZE :: OFFSETX ,
@@ -183,16 +178,15 @@ where
183178 self . set_draw_area (
184179 ( offset_x, SIZE :: OFFSETY ) ,
185180 ( SIZE :: WIDTH + offset_x, SIZE :: HEIGHT + SIZE :: OFFSETY ) ,
186- )
187- . terminal_err ( ) ?;
181+ ) ?;
188182
189183 // Clear the display
190184 for _ in 0 ..SIZE :: CHAR_NUM {
191- self . draw ( & [ 0 ; 8 ] ) . terminal_err ( ) ?;
185+ self . draw ( & [ 0 ; 8 ] ) ?;
192186 }
193187
194188 // But for normal operation we manage the line wrapping
195- self . set_addr_mode ( AddrMode :: Page ) . terminal_err ( ) ?;
189+ self . set_addr_mode ( AddrMode :: Page ) ?;
196190 self . reset_pos ( ) ?;
197191
198192 Ok ( ( ) )
@@ -203,11 +197,11 @@ where
203197 match c {
204198 '\n' => {
205199 let CursorWrapEvent ( new_line) = self . ensure_cursor ( ) ?. advance_line ( ) ;
206- self . set_column ( 0 ) . terminal_err ( ) ?;
207- self . set_row ( new_line * 8 ) . terminal_err ( ) ?;
200+ self . set_column ( 0 ) ?;
201+ self . set_row ( new_line * 8 ) ?;
208202 }
209203 '\r' => {
210- self . set_column ( 0 ) . terminal_err ( ) ?;
204+ self . set_column ( 0 ) ?;
211205 let ( _, cur_line) = self . ensure_cursor ( ) ?. get_position ( ) ;
212206 self . ensure_cursor ( ) ?. set_position ( 0 , cur_line) ;
213207 }
@@ -222,7 +216,7 @@ where
222216 }
223217 } ;
224218
225- self . draw ( & bitmap) . terminal_err ( ) ?;
219+ self . draw ( & bitmap) ?;
226220
227221 // Increment character counter and potentially wrap line
228222 self . advance_cursor ( ) ?;
@@ -260,12 +254,12 @@ where
260254 } ;
261255 match self . rotation ( ) {
262256 DisplayRotation :: Rotate0 | DisplayRotation :: Rotate180 => {
263- self . set_column ( offset_x + column * 8 ) . terminal_err ( ) ?;
264- self . set_row ( SIZE :: OFFSETY + row * 8 ) . terminal_err ( ) ?;
257+ self . set_column ( offset_x + column * 8 ) ?;
258+ self . set_row ( SIZE :: OFFSETY + row * 8 ) ?;
265259 }
266260 DisplayRotation :: Rotate90 | DisplayRotation :: Rotate270 => {
267- self . set_column ( offset_x + row * 8 ) . terminal_err ( ) ?;
268- self . set_row ( SIZE :: OFFSETY + column * 8 ) . terminal_err ( ) ?;
261+ self . set_column ( offset_x + row * 8 ) ?;
262+ self . set_row ( SIZE :: OFFSETY + column * 8 ) ?;
269263 }
270264 }
271265 self . ensure_cursor ( ) ?. set_position ( column, row) ;
0 commit comments