Resolve all Rust warnings
This commit is contained in:
41
src/main.rs
41
src/main.rs
@@ -2,8 +2,6 @@ extern crate bufstream;
|
|||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate image;
|
extern crate image;
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
@@ -13,16 +11,11 @@ use std::thread::JoinHandle;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use bufstream::BufStream;
|
use bufstream::BufStream;
|
||||||
use clap::{Arg, App, SubCommand};
|
use clap::{Arg, App};
|
||||||
use image::{GenericImage, DynamicImage, FilterType, Pixel, Primitive};
|
use image::{DynamicImage, FilterType, Pixel};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The target host
|
|
||||||
// const HOST: &'static str = "127.0.0.1:8080";
|
|
||||||
// const HOST: &'static str = "151.217.38.83:1234";
|
|
||||||
// const HOST: &'static str = "151.217.47.77:8080";
|
|
||||||
|
|
||||||
// The default thread count
|
// The default thread count
|
||||||
const DEFAULT_THREAD_COUNT: usize = 4;
|
const DEFAULT_THREAD_COUNT: usize = 4;
|
||||||
|
|
||||||
@@ -31,7 +24,7 @@ const DEFAULT_WIDTH: u32 = 1920;
|
|||||||
const DEFAULT_HEIGHT: u32 = 1080;
|
const DEFAULT_HEIGHT: u32 = 1080;
|
||||||
|
|
||||||
// The default size of the command output read buffer
|
// The default size of the command output read buffer
|
||||||
const CMD_READ_BUFFER_SIZE: usize = 16;
|
// const CMD_READ_BUFFER_SIZE: usize = 16;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -147,16 +140,15 @@ fn start(
|
|||||||
println!("Starting...");
|
println!("Starting...");
|
||||||
|
|
||||||
// Create a new pixelflut canvas
|
// Create a new pixelflut canvas
|
||||||
let canvas = PixCanvas::new(host, image_path, count, size, offset);
|
PixCanvas::new(host, image_path, count, size, offset);
|
||||||
|
|
||||||
// Sleep this thread
|
// Sleep this thread
|
||||||
thread::sleep(Duration::new(10000000, 0));
|
thread::sleep(Duration::new(99999999, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a stream to talk to the pixelflut server.
|
/// Create a stream to talk to the pixelflut server.
|
||||||
///
|
///
|
||||||
/// The stream is returned as result.
|
/// The stream is returned as result.
|
||||||
// TODO: Specify a host here!
|
|
||||||
fn create_stream(host: String) -> Result<TcpStream, Error> {
|
fn create_stream(host: String) -> Result<TcpStream, Error> {
|
||||||
TcpStream::connect(host)
|
TcpStream::connect(host)
|
||||||
}
|
}
|
||||||
@@ -232,7 +224,7 @@ impl PixCanvas {
|
|||||||
// Spawn some painters
|
// Spawn some painters
|
||||||
for i in 0..self.painter_count {
|
for i in 0..self.painter_count {
|
||||||
// Determine the slice width
|
// Determine the slice width
|
||||||
let width = (self.size.0 / (self.painter_count as u32));
|
let width = self.size.0 / (self.painter_count as u32);
|
||||||
|
|
||||||
// Define the area to paint per thread
|
// Define the area to paint per thread
|
||||||
let painter_area = Rect::from(
|
let painter_area = Rect::from(
|
||||||
@@ -277,7 +269,7 @@ impl PixCanvas {
|
|||||||
|
|
||||||
// Do some work
|
// Do some work
|
||||||
loop {
|
loop {
|
||||||
painter.work();
|
painter.work().expect("Painter failed to perform work");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -308,7 +300,7 @@ impl Painter {
|
|||||||
|
|
||||||
/// Perform work.
|
/// Perform work.
|
||||||
/// Paint the whole defined area.
|
/// Paint the whole defined area.
|
||||||
pub fn work(&mut self) {
|
pub fn work(&mut self) -> Result<(), Error> {
|
||||||
// Get an RGB image
|
// Get an RGB image
|
||||||
let image = self.image.to_rgb();
|
let image = self.image.to_rgb();
|
||||||
|
|
||||||
@@ -333,9 +325,12 @@ impl Painter {
|
|||||||
x + self.area.x + self.offset.0,
|
x + self.area.x + self.offset.0,
|
||||||
y + self.area.y + self.offset.1,
|
y + self.area.y + self.offset.1,
|
||||||
&color,
|
&color,
|
||||||
);
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Everything seems to be ok
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,7 +352,7 @@ impl PixClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write a pixel to the given stream.
|
/// Write a pixel to the given stream.
|
||||||
fn write_pixel(&mut self, x: u32, y: u32, color: &Color) {
|
fn write_pixel(&mut self, x: u32, y: u32, color: &Color) -> Result<(), Error> {
|
||||||
// Write the command to set a pixel
|
// Write the command to set a pixel
|
||||||
self.write_command(
|
self.write_command(
|
||||||
format!("PX {} {} {}", x, y, color.as_hex()),
|
format!("PX {} {} {}", x, y, color.as_hex()),
|
||||||
@@ -376,9 +371,13 @@ impl PixClient {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/// Write the given command to the given stream.
|
/// Write the given command to the given stream.
|
||||||
fn write_command(&mut self, cmd: String) {
|
fn write_command(&mut self, cmd: String) -> Result<(), Error> {
|
||||||
self.stream.write(cmd.as_bytes());
|
// Write the pixels and a new line
|
||||||
self.stream.write("\n".as_bytes());
|
self.stream.write(cmd.as_bytes())?;
|
||||||
|
self.stream.write("\n".as_bytes())?;
|
||||||
|
|
||||||
|
// Everything seems to be ok
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Write the given command to the given stream, and read the output.
|
// /// Write the given command to the given stream, and read the output.
|
||||||
|
|||||||
Reference in New Issue
Block a user