diff --git a/src/app.rs b/src/app.rs index 0b6ba5a..d79dc36 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,8 +1,8 @@ // Application properties -pub const APP_NAME: &'static str = "pixelpwnr"; -pub const APP_VERSION: &'static str = "0.1"; -pub const APP_AUTHOR: &'static str = "Tim Visee "; -pub const APP_ABOUT: &'static str = "A quick pixelflut client, that pwns pixelflut panels."; +pub const APP_NAME: &str = "pixelpwnr"; +pub const APP_VERSION: &str = "0.1"; +pub const APP_AUTHOR: &str = "Tim Visee "; +pub const APP_ABOUT: &str = "A quick pixelflut client, that pwns pixelflut panels."; // The default frames per second rate pub const DEFAULT_IMAGE_FPS: u32 = 1; diff --git a/src/arg_handler.rs b/src/arg_handler.rs index e44f0a0..2ee3ddc 100644 --- a/src/arg_handler.rs +++ b/src/arg_handler.rs @@ -100,7 +100,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> { self.matches .value_of("count") .map(|count| count.parse::().expect("Invalid count specified")) - .unwrap_or(num_cpus::get()) + .unwrap_or_else(num_cpus::get) } /// Get the image paths. diff --git a/src/color.rs b/src/color.rs index 2a648db..0c5c73f 100644 --- a/src/color.rs +++ b/src/color.rs @@ -18,7 +18,7 @@ impl Color { /// Get a hexadecimal representation of the color, /// such as `FFFFFF` for white and `FF0000` for red. - pub fn as_hex(&self) -> String { + pub fn as_hex(self) -> String { format!("{:02X}{:02X}{:02X}", self.r, self.g, self.b) } } diff --git a/src/image_manager.rs b/src/image_manager.rs index 24c207f..464438c 100644 --- a/src/image_manager.rs +++ b/src/image_manager.rs @@ -26,13 +26,13 @@ impl ImageManager { } /// Instantiate the image manager, and load the images from the given paths. - pub fn load(paths: Vec<&str>, size: &(u32, u32)) -> ImageManager { + pub fn load(paths: &[&str], size: (u32, u32)) -> ImageManager { // Show a status message println!("Load and process {} image(s)...", paths.len()); // Load the images from the paths let image_manager = - ImageManager::from(paths.iter().map(|path| load_image(path, &size)).collect()); + ImageManager::from(paths.iter().map(|path| load_image(path, size)).collect()); // TODO: process the image slices @@ -82,7 +82,7 @@ impl ImageManager { } /// Load the image at the given path, and size it correctly -fn load_image(path: &str, size: &(u32, u32)) -> DynamicImage { +fn load_image(path: &str, size: (u32, u32)) -> DynamicImage { // Create a path instance let path = Path::new(&path); diff --git a/src/main.rs b/src/main.rs index 7194d0e..e2896e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ fn start<'a>(arg_handler: &ArgHandler<'a>) { ); // Load the image manager - let mut image_manager = ImageManager::load(arg_handler.image_paths(), &size); + let mut image_manager = ImageManager::load(&arg_handler.image_paths(), size); // Start the work in the image manager, to walk through the frames image_manager.work(&mut canvas, arg_handler.fps()); diff --git a/src/painter/painter.rs b/src/painter/painter.rs index 388053f..c3bbeb7 100644 --- a/src/painter/painter.rs +++ b/src/painter/painter.rs @@ -74,7 +74,7 @@ impl Painter { self.client.write_pixel( x + self.area.x + self.offset.0, y + self.area.y + self.offset.1, - &color, + color, )?; } } diff --git a/src/pix/client.rs b/src/pix/client.rs index 186d29a..4e16648 100644 --- a/src/pix/client.rs +++ b/src/pix/client.rs @@ -16,7 +16,7 @@ use color::Color; const CMD_READ_BUFFER_SIZE: usize = 32; // The response format of the screen size from a pixelflut server. -const PIX_SERVER_SIZE_REGEX: &'static str = r"^(?i)\s*SIZE\s+([[:digit:]]+)\s+([[:digit:]]+)\s*$"; +const PIX_SERVER_SIZE_REGEX: &str = r"^(?i)\s*SIZE\s+([[:digit:]]+)\s+([[:digit:]]+)\s*$"; /// A pixelflut client. /// @@ -44,9 +44,9 @@ impl Client { } /// Write a pixel to the given stream. - pub fn write_pixel(&mut self, x: u32, y: u32, color: &Color) -> Result<(), Error> { + pub fn write_pixel(&mut self, x: u32, y: u32, color: Color) -> Result<(), Error> { // Write the command to set a pixel - self.write_command(format!("PX {} {} {}", x, y, color.as_hex())) + self.write_command(&format!("PX {} {} {}", x, y, color.as_hex())) } /// Read the size of the screen. @@ -77,10 +77,10 @@ impl Client { } /// Write the given command to the given stream. - fn write_command(&mut self, cmd: String) -> Result<(), Error> { + fn write_command(&mut self, cmd: &str) -> Result<(), Error> { // Write the pixels and a new line - self.stream.write(cmd.as_bytes())?; - self.stream.write("\r\n".as_bytes())?; + self.stream.write_all(cmd.as_bytes())?; + self.stream.write_all(b"\r\n")?; // Flush, make sure to clear the send buffer // TODO: only flush each 100 pixels? @@ -95,7 +95,7 @@ impl Client { } /// Write the given command to the given stream, and read the output. - fn write_read_command(&mut self, cmd: String) -> Result { + fn write_read_command(&mut self, cmd: &str) -> Result { // Write the command self.write_command(cmd)?;