From 29494ca7a8af8589a1f73e813c29365339006810 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Wed, 26 Feb 2025 10:49:43 +0700 Subject: upd: type alias --- src/main.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 0c81220..f81c5a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ use std::io::Write; const IMG_WIDTH: usize = 256; const IMG_HEIGHT: usize = 256; +type DisplayBuffer = [[Pixel; IMG_WIDTH]; IMG_HEIGHT]; + #[derive(Debug, Copy, Clone)] struct Pixel { r: u8, @@ -18,8 +20,8 @@ impl Default for Pixel { } struct View<'a> { - data: &'a[[Pixel; IMG_WIDTH]; IMG_HEIGHT], - viewer: fn(&[[Pixel; IMG_WIDTH]; IMG_HEIGHT]) -> Result, + data: &'a DisplayBuffer, + viewer: fn(&DisplayBuffer) -> Result, } impl<'a> View<'a> { @@ -36,7 +38,7 @@ impl<'a> View<'a> { } } -fn ppm_exporter(data: &[[Pixel; IMG_WIDTH]; IMG_HEIGHT]) -> Result { +fn ppm_exporter(data: &DisplayBuffer) -> Result { let file_name = "output.ppm"; let mut file = File::create(file_name)?; // header @@ -53,8 +55,18 @@ fn ppm_exporter(data: &[[Pixel; IMG_WIDTH]; IMG_HEIGHT]) -> Result