Skip to content

Commit 9a2916e

Browse files
authored
Remove unwraps, replace with as coercion (#105)
* Remove unwraps, replace with `as` coercion * Changelog entry
1 parent f5f2fab commit 9a2916e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
## [Unreleased] - ReleaseDate
88

9+
### Changed
10+
11+
- [#105](https://github.com/jamwaffles/ssd1306/pull/105) Reduce flash usage by around 400 bytes by replacing some internal `unwrap()`s with `as` coercions.
12+
913
## [0.3.0-alpha.4] - 2020-02-07
1014

1115
### Added

src/mode/graphics.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ where
275275
}
276276
}
277277

278-
#[cfg(feature = "graphics")]
279-
use core::convert::TryInto;
280278
#[cfg(feature = "graphics")]
281279
use embedded_graphics::{
282280
drawable,
@@ -297,16 +295,13 @@ where
297295
let drawable::Pixel(pos, color) = pixel;
298296

299297
// Guard against negative values. All positive i32 values from `pos` can be represented in
300-
// the `u32`s that `set_pixel()` accepts.
298+
// the `u32`s that `set_pixel()` accepts...
301299
if pos.x < 0 || pos.y < 0 {
302300
return;
303301
}
304302

305-
self.set_pixel(
306-
(pos.x).try_into().unwrap(),
307-
(pos.y).try_into().unwrap(),
308-
RawU1::from(color).into_inner(),
309-
);
303+
// ... which makes the `as` coercions here safe.
304+
self.set_pixel(pos.x as u32, pos.y as u32, RawU1::from(color).into_inner());
310305
}
311306

312307
fn size(&self) -> Size {

0 commit comments

Comments
 (0)