Fix more clippy warnings

This commit is contained in:
Austen Adler 2021-08-21 16:27:57 -04:00
parent 489adc1af1
commit 49f7774d66
7 changed files with 17 additions and 17 deletions

View File

@ -16,4 +16,5 @@ rust-embed="6.0.0"
hex = "0.4.3" hex = "0.4.3"
serde_json = "1" serde_json = "1"
live-view = { path = "./liveview-rust/" } live-view = { path = "./liveview-rust/" }
askama = "0.10.5" # askama = "0.10.5"
askama = { git = "https://github.com/djc/askama", rev = "017b590" }

View File

@ -2,8 +2,6 @@
// #![allow(dead_code, unused_imports)] // #![allow(dead_code, unused_imports)]
// Enable clippy 'hard mode' // Enable clippy 'hard mode'
#![warn(clippy::all, clippy::pedantic, clippy::nursery)] #![warn(clippy::all, clippy::pedantic, clippy::nursery)]
// Intended behavior (10_f64 as i32)
// #![allow(clippy::cast_possible_truncation)]
#![allow( #![allow(
// Cannot be fixed // Cannot be fixed
clippy::multiple_crate_versions, clippy::multiple_crate_versions,
@ -79,7 +77,7 @@ fn main() -> ProgramResult<()> {
Ok(errors::Message::String(s)) => println!("\r{}", s), Ok(errors::Message::String(s)) => println!("\r{}", s),
Ok(errors::Message::Error(e)) => println!("\rError!! {:?}", e), Ok(errors::Message::Error(e)) => println!("\rError!! {:?}", e),
Ok(errors::Message::Terminated) => { Ok(errors::Message::Terminated) => {
panic!("A thread terminated") panic!("A thread terminated");
} }
Ok(errors::Message::InputPrompt(i)) => input_prompt = Some(i), Ok(errors::Message::InputPrompt(i)) => input_prompt = Some(i),
Err(e) => { Err(e) => {
@ -92,7 +90,7 @@ fn main() -> ProgramResult<()> {
if let Some(ref s) = input_prompt { if let Some(ref s) = input_prompt {
print!("{}: ", s); print!("{}: ", s);
// We do not care if we can't flush // We do not care if we can't flush
let _ = io::stdout().flush(); let _drop = io::stdout().flush();
} }
} }
} }

View File

@ -56,8 +56,8 @@ impl LedStrip {
let num_lights = config.num_lights; let num_lights = config.num_lights;
let mut ret = Self { let mut ret = Self {
adapter, adapter,
pattern,
config, config,
pattern,
}; };
ret.set_num_lights(num_lights); ret.set_num_lights(num_lights);
Ok(ret) Ok(ret)
@ -120,7 +120,7 @@ impl LedStrip {
if pat.init(self.config.num_lights).is_ok() { if pat.init(self.config.num_lights).is_ok() {
self.pattern = pat; self.pattern = pat;
} else { } else {
let _ = message_tx.send(errors::Message::String(format!( let _result = message_tx.send(errors::Message::String(format!(
"Clearing light strip: {:?}", "Clearing light strip: {:?}",
pat pat
))); )));
@ -131,7 +131,7 @@ impl LedStrip {
if pat.init(self.config.num_lights).is_ok() { if pat.init(self.config.num_lights).is_ok() {
self.pattern = pat; self.pattern = pat;
} else { } else {
let _ = message_tx.send(errors::Message::String(format!( let _result = message_tx.send(errors::Message::String(format!(
"Error initializing pattern: {:?}", "Error initializing pattern: {:?}",
pat pat
))); )));
@ -142,7 +142,7 @@ impl LedStrip {
} }
Message::SetTickTime(tick_time_ms) => { Message::SetTickTime(tick_time_ms) => {
if tick_time_ms < MIN_TICK_TIME { if tick_time_ms < MIN_TICK_TIME {
let _ = message_tx.send(errors::Message::String(format!( let _result = message_tx.send(errors::Message::String(format!(
"Error with tick time: {}", "Error with tick time: {}",
tick_time_ms tick_time_ms
))); )));
@ -157,7 +157,7 @@ impl LedStrip {
if pat.init(self.config.num_lights).is_ok() { if pat.init(self.config.num_lights).is_ok() {
self.pattern = Box::new(pat); self.pattern = Box::new(pat);
} else { } else {
let _ = message_tx.send(errors::Message::String(String::from( let _result = message_tx.send(errors::Message::String(String::from(
"Could not construct clear pattern", "Could not construct clear pattern",
))); )));
} }
@ -174,7 +174,7 @@ impl LedStrip {
} }
if exit { if exit {
let _ = message_tx.send(errors::Message::String(String::from( let _result = message_tx.send(errors::Message::String(String::from(
"Exiting as requested", "Exiting as requested",
))); )));
process::exit(0); process::exit(0);

View File

@ -22,6 +22,6 @@ pub struct ControlTemplate {
} }
impl live_view::Template for ControlTemplate { impl live_view::Template for ControlTemplate {
fn render(&self) -> Result<String, Box<dyn std::error::Error>> { fn render(&self) -> Result<String, Box<dyn std::error::Error>> {
Ok(<Self as askama::Template>::render(&self)?) Ok(<Self as askama::Template>::render(self)?)
} }
} }

View File

@ -132,7 +132,7 @@ fn change_pattern(
} }
fn get_line(message_tx: &Sender<errors::Message>, prompt: &str) -> ProgramResult<String> { fn get_line(message_tx: &Sender<errors::Message>, prompt: &str) -> ProgramResult<String> {
let _ = message_tx.send(errors::Message::InputPrompt(String::from(prompt))); let _drop = message_tx.send(errors::Message::InputPrompt(String::from(prompt)));
std::io::stdout() std::io::stdout()
.flush() .flush()
.map_err(|_| ProgramError::UiError(String::from("Could not flush stdout")))?; .map_err(|_| ProgramError::UiError(String::from("Could not flush stdout")))?;

View File

@ -39,7 +39,7 @@ pub async fn start(
message_tx: Sender<errors::Message>, message_tx: Sender<errors::Message>,
strip_tx: Sender<strip::Message>, strip_tx: Sender<strip::Message>,
) -> std::io::Result<()> { ) -> std::io::Result<()> {
let _ = message_tx.send(errors::Message::String(String::from("Starting webui"))); let _drop = message_tx.send(errors::Message::String(String::from("Starting webui")));
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
.data(AppState { .data(AppState {
@ -49,7 +49,7 @@ pub async fn start(
web::scope("/api") web::scope("/api")
.app_data( .app_data(
JsonConfig::default().error_handler(|err: JsonPayloadError, _req| { JsonConfig::default().error_handler(|err: JsonPayloadError, _req| {
// let _ = message_tx.send(errors::Message::String(format!("JSON error: {:?}", err))); // let _drop = message_tx.send(errors::Message::String(format!("JSON error: {:?}", err)));
println!("JSON error: {:?}", err); println!("JSON error: {:?}", err);
err.into() err.into()
}), }),

View File

@ -1,9 +1,10 @@
<!-- TODO: Do not use .to_string() for comparison -->
<!-- TODO: When refreshing, the selected element does not change --> <!-- TODO: When refreshing, the selected element does not change -->
<select rust-input="change-template"> <select rust-input="change-template">
{% let selected_name = parameters.get_name() %}
{% for name in Parameters::get_names() %} {% for name in Parameters::get_names() %}
<option value="{{ name }}" <option value="{{ name }}"
{% if name.to_string() == parameters.get_name() -%} <!-- TODO: Do not use .to_string() for comparison -->
{% if selected_name == name.to_string() -%}
selected="selected" selected="selected"
{%- endif -%} {%- endif -%}
>{{ name }}</option> >{{ name }}</option>