@@ -112,14 +112,9 @@ impl core::fmt::Debug for TerminalModeError {
112
112
}
113
113
}
114
114
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)
123
118
}
124
119
}
125
120
@@ -147,7 +142,7 @@ where
147
142
///
148
143
/// This method resets the cursor but does not clear the screen.
149
144
fn set_rotation ( & mut self , rot : DisplayRotation ) -> Result < ( ) , TerminalModeError > {
150
- self . set_rotation ( rot) . terminal_err ( ) ?;
145
+ self . set_rotation ( rot) ?;
151
146
// Need to reset cursor position, otherwise coordinates can become invalid
152
147
self . reset_pos ( )
153
148
}
@@ -156,7 +151,7 @@ where
156
151
/// column 0 on the left and column _(SIZE::Width::U8 - 1)_ on the right, but no automatic line
157
152
/// wrapping.
158
153
fn init ( & mut self ) -> Result < ( ) , TerminalModeError > {
159
- self . init_with_addr_mode ( AddrMode :: Page ) . terminal_err ( ) ?;
154
+ self . init_with_addr_mode ( AddrMode :: Page ) ?;
160
155
self . reset_pos ( ) ?;
161
156
Ok ( ( ) )
162
157
}
@@ -170,7 +165,7 @@ where
170
165
/// Clear the display and reset the cursor to the top left corner
171
166
pub fn clear ( & mut self ) -> Result < ( ) , TerminalModeError > {
172
167
// 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 ) ?;
174
169
175
170
let offset_x = match self . rotation ( ) {
176
171
DisplayRotation :: Rotate0 | DisplayRotation :: Rotate270 => SIZE :: OFFSETX ,
@@ -183,16 +178,15 @@ where
183
178
self . set_draw_area (
184
179
( offset_x, SIZE :: OFFSETY ) ,
185
180
( SIZE :: WIDTH + offset_x, SIZE :: HEIGHT + SIZE :: OFFSETY ) ,
186
- )
187
- . terminal_err ( ) ?;
181
+ ) ?;
188
182
189
183
// Clear the display
190
184
for _ in 0 ..SIZE :: CHAR_NUM {
191
- self . draw ( & [ 0 ; 8 ] ) . terminal_err ( ) ?;
185
+ self . draw ( & [ 0 ; 8 ] ) ?;
192
186
}
193
187
194
188
// 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 ) ?;
196
190
self . reset_pos ( ) ?;
197
191
198
192
Ok ( ( ) )
@@ -203,11 +197,11 @@ where
203
197
match c {
204
198
'\n' => {
205
199
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 ) ?;
208
202
}
209
203
'\r' => {
210
- self . set_column ( 0 ) . terminal_err ( ) ?;
204
+ self . set_column ( 0 ) ?;
211
205
let ( _, cur_line) = self . ensure_cursor ( ) ?. get_position ( ) ;
212
206
self . ensure_cursor ( ) ?. set_position ( 0 , cur_line) ;
213
207
}
@@ -222,7 +216,7 @@ where
222
216
}
223
217
} ;
224
218
225
- self . draw ( & bitmap) . terminal_err ( ) ?;
219
+ self . draw ( & bitmap) ?;
226
220
227
221
// Increment character counter and potentially wrap line
228
222
self . advance_cursor ( ) ?;
@@ -260,12 +254,12 @@ where
260
254
} ;
261
255
match self . rotation ( ) {
262
256
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 ) ?;
265
259
}
266
260
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 ) ?;
269
263
}
270
264
}
271
265
self . ensure_cursor ( ) ?. set_position ( column, row) ;
0 commit comments