From 48aeda6277dc78f64f33258b5c753e0fa8ab0d77 Mon Sep 17 00:00:00 2001 From: faineance Date: Sat, 14 Mar 2015 21:08:01 +0000 Subject: [PATCH] Fix rust ppm example --- .../Rust/bitmap-write-a-ppm-file.rust | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Task/Bitmap-Write-a-PPM-file/Rust/bitmap-write-a-ppm-file.rust b/Task/Bitmap-Write-a-PPM-file/Rust/bitmap-write-a-ppm-file.rust index 10a6e9950f..5e0e69a607 100644 --- a/Task/Bitmap-Write-a-PPM-file/Rust/bitmap-write-a-ppm-file.rust +++ b/Task/Bitmap-Write-a-PPM-file/Rust/bitmap-write-a-ppm-file.rust @@ -1,7 +1,6 @@ use std::vec::from_elem; -use std::path::posix::{Path}; -use std::io::File; - +use std::path::Path; +use std::fs::File; pub struct RGB { r: u8 ,g: u8 @@ -9,23 +8,23 @@ pub struct RGB { } pub struct PPM { - height: uint - ,width: uint - ,data: ~[u8] + height: usize + ,width: usize + ,data: [u8] } impl PPM { - pub fn new(height: uint, width: uint) -> PPM { + pub fn new(height: usize, width: usize) -> PPM { let size = 3 * height * width; let buffer = from_elem(size, 0u8); PPM{height: height, width: width, data: buffer} } - fn buffer_size(&self) -> uint { + fn buffer_size(&self) -> usize { 3 * self.height * self.width } - fn get_offset(&self, x: uint, y: uint) -> Option { + fn get_offset(&self, x: usize, y: usize) -> Option { let offset = (y * self.width * 3) + (x * 3); if(offset < self.buffer_size()){ Some(offset) @@ -34,19 +33,19 @@ impl PPM { } } - pub fn get_pixel(&self, x: uint, y: uint) -> Option { + pub fn get_pixel(&self, x: usize, y: usize) -> Option { match self.get_offset(x, y) { Some(offset) => { let r = self.data[offset]; let g = self.data[offset + 1]; let b = self.data[offset + 2]; - Some(RGB{r, g, b}) + Some(RGB{r: r, g: g, b: b}) }, None => None } } - pub fn set_pixel(&mut self, x: uint, y: uint, color: RGB) -> bool { + pub fn set_pixel(&mut self, x: usize, y: usize, color: RGB) -> bool { match self.get_offset(x, y) { Some(offset) => { self.data[offset] = color.r;