Skip to content

Commit

Permalink
Remove unwraps, replace with as coercion (#105)
Browse files Browse the repository at this point in the history
* Remove unwraps, replace with `as` coercion

* Changelog entry
  • Loading branch information
jamwaffles authored Feb 8, 2020
1 parent f5f2fab commit 9a2916e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

## [Unreleased] - ReleaseDate

### Changed

- [#105](https://github.com/jamwaffles/ssd1306/pull/105) Reduce flash usage by around 400 bytes by replacing some internal `unwrap()`s with `as` coercions.

## [0.3.0-alpha.4] - 2020-02-07

### Added
Expand Down
11 changes: 3 additions & 8 deletions src/mode/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ where
}
}

#[cfg(feature = "graphics")]
use core::convert::TryInto;
#[cfg(feature = "graphics")]
use embedded_graphics::{
drawable,
Expand All @@ -297,16 +295,13 @@ where
let drawable::Pixel(pos, color) = pixel;

// Guard against negative values. All positive i32 values from `pos` can be represented in
// the `u32`s that `set_pixel()` accepts.
// the `u32`s that `set_pixel()` accepts...
if pos.x < 0 || pos.y < 0 {
return;
}

self.set_pixel(
(pos.x).try_into().unwrap(),
(pos.y).try_into().unwrap(),
RawU1::from(color).into_inner(),
);
// ... which makes the `as` coercions here safe.
self.set_pixel(pos.x as u32, pos.y as u32, RawU1::from(color).into_inner());
}

fn size(&self) -> Size {
Expand Down

0 comments on commit 9a2916e

Please sign in to comment.