From c9683a2cd920cd3ccaa0e9c67640280c5a27feb7 Mon Sep 17 00:00:00 2001 From: proudmuslim-dev <69869443+proudmuslim-dev@users.noreply.github.com> Date: Sat, 27 Jan 2024 00:21:18 +0000 Subject: [PATCH] Fix typos in code for `embedded_graphics` crate in chapter 3 This still won't compile on account of the fact that the `Point` type apparently doesn't implement `Into<(usize, usize)>`. Attempting to change the type just results in more issues --- .../edition-3/posts/03-screen-output/index.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/blog/content/edition-3/posts/03-screen-output/index.md b/blog/content/edition-3/posts/03-screen-output/index.md index a7358682e..cc3e7c1c1 100644 --- a/blog/content/edition-3/posts/03-screen-output/index.md +++ b/blog/content/edition-3/posts/03-screen-output/index.md @@ -312,22 +312,24 @@ Fortunately, there is the nice `no_std`-compatible [`embedded-graphics`] crate, ```rust ,hl_lines=3 // in kernel/src/framebuffer.rs +use embedded_graphics::pixelcolor::Rgb888; pub struct Display { - framebuffer: Framebuffer, + framebuffer: FrameBuffer, } impl Display { - pub fn new(framebuffer: Framebuffer) -> Display { + pub fn new(framebuffer: FrameBuffer) -> Display { Self { framebuffer } } - fn draw_pixel(&mut self, pixel: Pixel) { + fn draw_pixel(&mut self, Pixel(coordinates, color): Pixel) { // ignore any pixels that are out of bounds. let (width, height) = { let info = self.framebuffer.info(); (info.width, info.height) } + if let Ok((x @ 0..width, y @ 0..height)) = coordinates.try_into() { let color = Color { red: color.r(), green: color.g(), blue: color.b()}; set_pixel_in(&mut self.framebuffer, Position { x, y }, color); @@ -336,7 +338,7 @@ impl Display { } impl embedded_graphics::draw_target::DrawTarget for Display { - type Color = embedded_graphics::pixelcolor::Rgb888; + type Color = Rgb888; /// Drawing operations can never fail. type Error = core::convert::Infallible; @@ -345,9 +347,10 @@ impl embedded_graphics::draw_target::DrawTarget for Display { where I: IntoIterator>, { - for Pixel(coordinates, color) in pixels.into_iter() { + for pixel in pixels.into_iter() { self.draw_pixel(pixel); } + Ok(()) } }