From 0e1e59476b72bfc269cc509cee81895d0d57384d Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Wed, 1 Feb 2017 10:42:36 +0100 Subject: [PATCH] Clippy + fmt. --- src/main.rs | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 09d2068..12e3f86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ extern crate getopts; extern crate rand; extern crate ansi_term; + use std::io; use std::io::prelude::*; use std::f32::consts::PI; @@ -11,6 +12,7 @@ use getopts::Options; use rand::{thread_rng, Rng}; use ansi_term::Colour::RGB; + fn print_usage(program: &str, opts: Options) { let brief = format!("Usage: {} [OPTION]... [FILE]...", program); @@ -28,10 +30,10 @@ fn main() { opts.optopt("S", "seed", "Rainbow seed, 0 = random", ""); opts.optflag("h", "help", "Show this message"); - // @todo do not panic! + // TODO Do not panic! let matches = match opts.parse(&args[1..]) { - Ok(m) => { m } - Err(f) => { panic!(f.to_string()) } + Ok(m) => m, + Err(f) => panic!(f.to_string()), }; // print usage? @@ -42,47 +44,44 @@ fn main() { } // get spread. - // @todo this is nasty... fix this. - let spread : f32 = match matches.opt_default("spread", "3.0") { + // TODO this is nasty... fix this. + let spread: f32 = match matches.opt_default("spread", "3.0") { Some(s) => { match s.parse() { - Ok(0.0) => 3.0, - Ok(n) => n, - _ => 3.0 + Ok(n) if n != 0.0 => n, + _ => 3.0, } - }, - None => 3.0 + } + None => 3.0, }; // get freq. - // @todo this is nasty... fix this. - let freq : f32 = match matches.opt_default("freq", "0.1") { + // TODO this is nasty... fix this. + let freq: f32 = match matches.opt_default("freq", "0.1") { Some(s) => { match s.parse() { - Ok(0.0) => 0.1, - Ok(n) => n, - _ => 0.1 + Ok(n) if n != 0.0 => n, + _ => 0.1, } - }, - None => 0.1 + } + None => 0.1, }; // get seed. - // @todo this is nasty... fix this. - let mut seed : i32 = match matches.opt_default("seed", "0") { + // TODO this is nasty... fix this. + let mut seed: i32 = match matches.opt_default("seed", "0") { Some(s) => { match s.parse() { - Ok(0) => thread_rng().gen_range(0, 256), - Ok(n) => n, - _ => thread_rng().gen_range(0, 256) + Ok(n) if n != 0 => n, + _ => thread_rng().gen_range(0, 256), } - }, - None => thread_rng().gen_range(0, 256) + } + None => thread_rng().gen_range(0, 256), }; let stdin = io::stdin(); - // @todo I want to use chars() instead, but it's unstable right now :( + // TODO I want to use chars() instead, but it's unstable right now :( for line in stdin.lock().lines() { seed += 1; @@ -96,7 +95,7 @@ fn main() { print!("{}", RGB(red, green, blue).paint(c.to_string())); } - print!("\n"); + println!(); } }