Fix clippy errors: first pass

This commit is contained in:
Cobrand
2017-05-03 09:15:54 +02:00
parent 95497ff682
commit f1a76882d6
13 changed files with 40 additions and 50 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
extern crate sdl2;
use sdl2::audio::{AudioCallback, AudioSpecDesired};
use sdl2::audio::AudioSpecDesired;
use std::time::Duration;
-2
View File
@@ -41,13 +41,11 @@ fn main() {
let device = audio_subsystem.open_playback(None, &desired_spec, |spec| {
let wav = AudioSpecWAV::load_wav(wav_file)
.ok()
.expect("Could not load test WAV file");
let cvt = AudioCVT::new(
wav.format, wav.channels, wav.freq,
spec.format, spec.channels, spec.freq)
.ok()
.expect("Could not convert WAV file");
let data = cvt.convert(wav.buffer().to_vec());
+13 -20
View File
@@ -35,7 +35,7 @@ mod game_of_life {
playground[((PLAYGROUND_WIDTH-2) + i* PLAYGROUND_WIDTH) as usize] = true;
}
for j in 2..(PLAYGROUND_WIDTH-2) {
playground[(1*PLAYGROUND_WIDTH + j) as usize] = true;
playground[(PLAYGROUND_WIDTH + j) as usize] = true;
playground[((PLAYGROUND_HEIGHT-2)*PLAYGROUND_WIDTH + j) as usize] = true;
}
@@ -54,7 +54,7 @@ mod game_of_life {
}
}
pub fn get_mut<'a>(&'a mut self, x: i32, y: i32) -> Option<&'a mut bool> {
pub fn get_mut(&mut self, x: i32, y: i32) -> Option<&mut bool> {
if x >= 0 && y >= 0 &&
(x as u32) < PLAYGROUND_WIDTH && (y as u32) < PLAYGROUND_HEIGHT {
Some(&mut self.playground[(x as u32 + (y as u32)* PLAYGROUND_WIDTH) as usize])
@@ -86,11 +86,8 @@ mod game_of_life {
if !(i == 0 && j == 0) {
let peek_x : i32 = (x as i32) + i;
let peek_y : i32 = (y as i32) + j;
match self.get(peek_x, peek_y) {
Some(true) => {
count += 1;
},
_ => {},
if let Some(true) = self.get(peek_x, peek_y) {
count += 1;
}
}
}
@@ -220,22 +217,18 @@ pub fn main() {
canvas.clear();
for (i, unit) in (&game).into_iter().enumerate() {
let i = i as u32;
match *unit {
true => {
canvas.copy(&square_texture,
None,
Rect::new(((i % PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
((i / PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
SQUARE_SIZE,
SQUARE_SIZE)).unwrap();
},
false => {},
if *unit {
canvas.copy(&square_texture,
None,
Rect::new(((i % PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
((i / PLAYGROUND_WIDTH) * SQUARE_SIZE) as i32,
SQUARE_SIZE,
SQUARE_SIZE)).unwrap();
}
}
canvas.present();
match game.state() {
game_of_life::State::Playing => { frame += 1; },
_ => {}
if let game_of_life::State::Playing = game.state() {
frame += 1;
};
}
}
+3 -4
View File
@@ -20,10 +20,9 @@ pub fn main() {
'running: loop {
for event in events.poll_iter() {
match event {
Event::Quit {..} => break 'running,
_ => ()
}
if let Event::Quit {..} = event {
break 'running;
};
}
// Create a set of pressed Keys.
+1 -1
View File
@@ -32,7 +32,7 @@ fn demo(filename: &Path) {
let format = AUDIO_S16LSB; // signed 16 bit samples, in little-endian byte order
let channels = 2; // Stereo
let chunk_size = 1024;
let _ = sdl2::mixer::open_audio(frequency, format, channels, chunk_size).unwrap();
sdl2::mixer::open_audio(frequency, format, channels, chunk_size).unwrap();
sdl2::mixer::allocate_channels(0);
{
+4 -2
View File
@@ -1,6 +1,7 @@
extern crate sdl2;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::collections::HashSet;
use std::time::Duration;
@@ -20,8 +21,9 @@ pub fn main() {
'running: loop {
for event in events.poll_iter() {
match event {
Event::Quit {..} => break 'running,
_ => ()
Event::KeyDown { keycode: Some(Keycode::Escape), .. } |
Event::Quit { .. } => break 'running,
_ => {}
}
}
+4 -2
View File
@@ -2,6 +2,7 @@ extern crate sdl2;
use sdl2::event::Event;
use sdl2::mouse::MouseButton;
use sdl2::keyboard::Keycode;
use std::time::Duration;
pub fn main() {
@@ -19,8 +20,9 @@ pub fn main() {
'running: loop {
for event in events.poll_iter() {
match event {
Event::Quit {..} => break 'running,
_ => ()
Event::KeyDown { keycode: Some(Keycode::Escape), .. } |
Event::Quit { .. } => break 'running,
_ => {}
}
}
+1 -1
View File
@@ -24,8 +24,8 @@ fn main() {
'mainloop: loop {
for event in sdl_context.event_pump().unwrap().poll_iter() {
match event {
Event::KeyDown { keycode: Some(Keycode::Escape), .. } |
Event::Quit { .. } => break 'mainloop,
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => break 'mainloop,
_ => {}
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ pub fn main() {
for y in 0..256 {
for x in 0..256 {
let offset = y*pitch + x*3;
buffer[offset + 0] = x as u8;
buffer[offset] = x as u8;
buffer[offset + 1] = y as u8;
buffer[offset + 2] = 0;
}
+1 -1
View File
@@ -43,8 +43,8 @@ fn main() {
'mainloop: loop {
for event in sdl_context.event_pump().unwrap().poll_iter() {
match event {
Event::KeyDown { keycode: Some(Keycode::Escape), .. } |
Event::Quit { .. } => break 'mainloop,
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => break 'mainloop,
_ => {}
}
}
+4 -4
View File
@@ -64,7 +64,7 @@ fn run(font_path: &Path) {
// render a surface, and convert it to a texture bound to the canvas
let surface = font.render("Hello Rust!")
.blended(Color::RGBA(255, 0, 0, 255)).unwrap();
let mut texture = texture_creator.create_texture_from_surface(&surface).unwrap();
let texture = texture_creator.create_texture_from_surface(&surface).unwrap();
canvas.set_draw_color(Color::RGBA(195, 217, 255, 255));
canvas.clear();
@@ -75,14 +75,14 @@ fn run(font_path: &Path) {
let padding = 64;
let target = get_centered_rect(width, height, SCREEN_WIDTH - padding, SCREEN_HEIGHT - padding);
canvas.copy(&mut texture, None, Some(target)).unwrap();
canvas.copy(&texture, None, Some(target)).unwrap();
canvas.present();
'mainloop: loop {
for event in sdl_context.event_pump().unwrap().poll_iter() {
match event {
Event::Quit{..} => break 'mainloop,
Event::KeyDown {keycode: Some(Keycode::Escape), ..} => break 'mainloop,
Event::KeyDown {keycode: Some(Keycode::Escape), ..} |
Event::Quit {..} => break 'mainloop,
_ => {}
}
}