Skip to content

Commit 359204c

Browse files
authored
refactor: simplify to io::Result (#1016)
Simplifies the code, logic stays exactly the same.
1 parent 14461c3 commit 359204c

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/backend/crossterm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ where
228228
Ok(Rect::new(0, 0, width, height))
229229
}
230230

231-
fn window_size(&mut self) -> Result<WindowSize, io::Error> {
231+
fn window_size(&mut self) -> io::Result<WindowSize> {
232232
let crossterm::terminal::WindowSize {
233233
columns,
234234
rows,

src/backend/termion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ where
198198
Ok(Rect::new(0, 0, terminal.0, terminal.1))
199199
}
200200

201-
fn window_size(&mut self) -> Result<WindowSize, io::Error> {
201+
fn window_size(&mut self) -> io::Result<WindowSize> {
202202
Ok(WindowSize {
203203
columns_rows: termion::terminal_size()?.into(),
204204
pixels: termion::terminal_size_pixels()?.into(),

src/backend/termwiz.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl TermwizBackend {
111111
}
112112

113113
impl Backend for TermwizBackend {
114-
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
114+
fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
115115
where
116116
I: Iterator<Item = (u16, u16, &'a Cell)>,
117117
{
@@ -181,13 +181,13 @@ impl Backend for TermwizBackend {
181181
Ok(())
182182
}
183183

184-
fn hide_cursor(&mut self) -> Result<(), io::Error> {
184+
fn hide_cursor(&mut self) -> io::Result<()> {
185185
self.buffered_terminal
186186
.add_change(Change::CursorVisibility(CursorVisibility::Hidden));
187187
Ok(())
188188
}
189189

190-
fn show_cursor(&mut self) -> Result<(), io::Error> {
190+
fn show_cursor(&mut self) -> io::Result<()> {
191191
self.buffered_terminal
192192
.add_change(Change::CursorVisibility(CursorVisibility::Visible));
193193
Ok(())
@@ -207,18 +207,18 @@ impl Backend for TermwizBackend {
207207
Ok(())
208208
}
209209

210-
fn clear(&mut self) -> Result<(), io::Error> {
210+
fn clear(&mut self) -> io::Result<()> {
211211
self.buffered_terminal
212212
.add_change(Change::ClearScreen(termwiz::color::ColorAttribute::Default));
213213
Ok(())
214214
}
215215

216-
fn size(&self) -> Result<Rect, io::Error> {
216+
fn size(&self) -> io::Result<Rect> {
217217
let (cols, rows) = self.buffered_terminal.dimensions();
218218
Ok(Rect::new(0, 0, u16_max(cols), u16_max(rows)))
219219
}
220220

221-
fn window_size(&mut self) -> Result<WindowSize, io::Error> {
221+
fn window_size(&mut self) -> io::Result<WindowSize> {
222222
let ScreenSize {
223223
cols,
224224
rows,
@@ -241,7 +241,7 @@ impl Backend for TermwizBackend {
241241
})
242242
}
243243

244-
fn flush(&mut self) -> Result<(), io::Error> {
244+
fn flush(&mut self) -> io::Result<()> {
245245
self.buffered_terminal
246246
.flush()
247247
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;

src/backend/test.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Display for TestBackend {
114114
}
115115

116116
impl Backend for TestBackend {
117-
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
117+
fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
118118
where
119119
I: Iterator<Item = (u16, u16, &'a Cell)>,
120120
{
@@ -125,26 +125,26 @@ impl Backend for TestBackend {
125125
Ok(())
126126
}
127127

128-
fn hide_cursor(&mut self) -> Result<(), io::Error> {
128+
fn hide_cursor(&mut self) -> io::Result<()> {
129129
self.cursor = false;
130130
Ok(())
131131
}
132132

133-
fn show_cursor(&mut self) -> Result<(), io::Error> {
133+
fn show_cursor(&mut self) -> io::Result<()> {
134134
self.cursor = true;
135135
Ok(())
136136
}
137137

138-
fn get_cursor(&mut self) -> Result<(u16, u16), io::Error> {
138+
fn get_cursor(&mut self) -> io::Result<(u16, u16)> {
139139
Ok(self.pos)
140140
}
141141

142-
fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> {
142+
fn set_cursor(&mut self, x: u16, y: u16) -> io::Result<()> {
143143
self.pos = (x, y);
144144
Ok(())
145145
}
146146

147-
fn clear(&mut self) -> Result<(), io::Error> {
147+
fn clear(&mut self) -> io::Result<()> {
148148
self.buffer.reset();
149149
Ok(())
150150
}
@@ -214,11 +214,11 @@ impl Backend for TestBackend {
214214
Ok(())
215215
}
216216

217-
fn size(&self) -> Result<Rect, io::Error> {
217+
fn size(&self) -> io::Result<Rect> {
218218
Ok(Rect::new(0, 0, self.width, self.height))
219219
}
220220

221-
fn window_size(&mut self) -> Result<WindowSize, io::Error> {
221+
fn window_size(&mut self) -> io::Result<WindowSize> {
222222
// Some arbitrary window pixel size, probably doesn't need much testing.
223223
static WINDOW_PIXEL_SIZE: Size = Size {
224224
width: 640,
@@ -230,7 +230,7 @@ impl Backend for TestBackend {
230230
})
231231
}
232232

233-
fn flush(&mut self) -> Result<(), io::Error> {
233+
fn flush(&mut self) -> io::Result<()> {
234234
Ok(())
235235
}
236236
}

0 commit comments

Comments
 (0)