add clippy lints

This commit is contained in:
Alex Janka 2025-01-10 09:59:30 +11:00
parent 9e19f669c5
commit 0b53d347dc
8 changed files with 41 additions and 18 deletions

View file

@ -9,6 +9,21 @@ version = "1.9.9-pre-20"
[workspace.lints.clippy] [workspace.lints.clippy]
pedantic = "warn" pedantic = "warn"
branches_sharing_code = "warn"
derive_partial_eq_without_eq = "warn"
equatable_if_let = "warn"
fallible_impl_from = "warn"
large_stack_frames = "warn"
missing_const_for_fn = "warn"
needless_collect = "warn"
needless_pass_by_ref_mut = "warn"
or_fun_call = "warn"
redundant_clone = "warn"
significant_drop_in_scrutinee = "warn"
significant_drop_tightening = "warn"
too_long_first_doc_paragraph = "warn"
trait_duplication_in_bounds = "warn"
cast-possible-truncation = { level = "allow", priority = 1 } cast-possible-truncation = { level = "allow", priority = 1 }
cast-precision-loss = { level = "allow", priority = 1 } cast-precision-loss = { level = "allow", priority = 1 }
default-trait-access = { level = "allow", priority = 1 } default-trait-access = { level = "allow", priority = 1 }

View file

@ -73,7 +73,7 @@ impl ConfigWatcher {
async fn overwrite_config(config: Config) -> eyre::Result<()> { async fn overwrite_config(config: Config) -> eyre::Result<()> {
let mut h = CONFIG let mut h = CONFIG
.get() .get()
.ok_or(eyre::eyre!("could not get config"))? .ok_or_else(|| eyre::eyre!("could not get config"))?
.write() .write()
.await; .await;
if h.charge_controllers != config.charge_controllers if h.charge_controllers != config.charge_controllers
@ -82,6 +82,7 @@ async fn overwrite_config(config: Config) -> eyre::Result<()> {
log::warn!("charge controller configuration changed on disk; please restart"); log::warn!("charge controller configuration changed on disk; please restart");
} }
*h = config; *h = config;
drop(h);
Ok(()) Ok(())
} }
@ -162,7 +163,7 @@ impl ConfigStorage {
} }
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(default)] #[serde(default)]
pub struct Config { pub struct Config {
pub primary_charge_controller: String, pub primary_charge_controller: String,
@ -183,7 +184,7 @@ impl Config {
} }
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ChargeControllerConfig { pub struct ChargeControllerConfig {
pub name: String, pub name: String,
pub watch_interval_seconds: u64, pub watch_interval_seconds: u64,
@ -193,13 +194,13 @@ pub struct ChargeControllerConfig {
pub transport: Transport, pub transport: Transport,
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub enum ChargeControllerVariant { pub enum ChargeControllerVariant {
Tristar, Tristar,
Pl { timeout_milliseconds: u64 }, Pl { timeout_milliseconds: u64 },
} }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum Transport { pub enum Transport {
Serial { port: String, baud_rate: u32 }, Serial { port: String, baud_rate: u32 },

View file

@ -118,7 +118,7 @@ impl Controller {
Ok(()) Ok(())
} }
pub fn timeout_interval(&self) -> std::time::Duration { pub const fn timeout_interval(&self) -> std::time::Duration {
self.interval self.interval
} }

View file

@ -260,7 +260,7 @@ impl Pli {
Ok(()) Ok(())
} }
fn flush(&mut self) -> eyre::Result<()> { fn flush(&self) -> eyre::Result<()> {
self.port.clear(tokio_serial::ClearBuffer::All)?; self.port.clear(tokio_serial::ClearBuffer::All)?;
Ok(()) Ok(())
} }
@ -286,9 +286,11 @@ impl Pli {
} }
} }
Err(last_err.unwrap_or(eyre::eyre!( Err(last_err.unwrap_or_else(|| {
"no error was stored in read_ram_with_retries: this should be unreachable??" eyre::eyre!(
))) "no error was stored in read_ram_with_retries: this should be unreachable??"
)
}))
} }
async fn read_ram_single<T>(&mut self, address: T) -> eyre::Result<u8> async fn read_ram_single<T>(&mut self, address: T) -> eyre::Result<u8>
@ -398,6 +400,6 @@ impl From<PlRamAddress> for u8 {
} }
} }
fn command(operation: u8, address: u8, data: u8) -> [u8; 4] { const fn command(operation: u8, address: u8, data: u8) -> [u8; 4] {
[operation, address, data, !operation] [operation, address, data, !operation]
} }

View file

@ -216,7 +216,7 @@ impl ChargeStateGauges {
} }
} }
fn zero_all(&mut self) { fn zero_all(&self) {
self.start.set(0); self.start.set(0);
self.night_check.set(0); self.night_check.set(0);
self.disconnect.set(0); self.disconnect.set(0);
@ -230,7 +230,7 @@ impl ChargeStateGauges {
self.unknown.set(0); self.unknown.set(0);
} }
fn set(&mut self, state: ChargeState) { fn set(&self, state: ChargeState) {
match state { match state {
ChargeState::Start => { ChargeState::Start => {
self.zero_all(); self.zero_all();

View file

@ -131,6 +131,8 @@ async fn watch(args: Args) -> eyre::Result<()> {
primary.set_tx_to_secondary(follow_voltage_tx.clone()); primary.set_tx_to_secondary(follow_voltage_tx.clone());
} }
drop(config);
let controller_tasks = futures::stream::FuturesUnordered::new(); let controller_tasks = futures::stream::FuturesUnordered::new();
for controller in controllers { for controller in controllers {
controller_tasks.push(run_loop(controller)); controller_tasks.push(run_loop(controller));

View file

@ -87,7 +87,8 @@ async fn all_interfaces(
let mut data = Vec::new(); let mut data = Vec::new();
for (k, v) in &state.map { for (k, v) in &state.map {
if let Some(v) = v.read().await.as_ref() { let v = v.read().await;
if let Some(v) = v.as_ref() {
data.push((k.clone(), v.common().clone())); data.push((k.clone(), v.common().clone()));
} }
} }

View file

@ -51,10 +51,12 @@ impl Handler for UiStatic {
data: v.contents().to_vec(), data: v.contents().to_vec(),
name: p, name: p,
}) })
.or(UI_DIR_FILES.get_file(&plus_index).map(|v| RawHtml { .or_else(|| {
data: v.contents().to_vec(), UI_DIR_FILES.get_file(&plus_index).map(|v| RawHtml {
name: plus_index, data: v.contents().to_vec(),
})); name: plus_index,
})
});
file.respond_to(req).or_forward((data, Status::NotFound)) file.respond_to(req).or_forward((data, Status::NotFound))
} }
} }