add clippy lints
This commit is contained in:
parent
9e19f669c5
commit
0b53d347dc
8 changed files with 41 additions and 18 deletions
15
Cargo.toml
15
Cargo.toml
|
@ -9,6 +9,21 @@ version = "1.9.9-pre-20"
|
|||
[workspace.lints.clippy]
|
||||
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-precision-loss = { level = "allow", priority = 1 }
|
||||
default-trait-access = { level = "allow", priority = 1 }
|
||||
|
|
|
@ -73,7 +73,7 @@ impl ConfigWatcher {
|
|||
async fn overwrite_config(config: Config) -> eyre::Result<()> {
|
||||
let mut h = CONFIG
|
||||
.get()
|
||||
.ok_or(eyre::eyre!("could not get config"))?
|
||||
.ok_or_else(|| eyre::eyre!("could not get config"))?
|
||||
.write()
|
||||
.await;
|
||||
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");
|
||||
}
|
||||
*h = config;
|
||||
drop(h);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -162,7 +163,7 @@ impl ConfigStorage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
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 name: String,
|
||||
pub watch_interval_seconds: u64,
|
||||
|
@ -193,13 +194,13 @@ pub struct ChargeControllerConfig {
|
|||
pub transport: Transport,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum ChargeControllerVariant {
|
||||
Tristar,
|
||||
Pl { timeout_milliseconds: u64 },
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Transport {
|
||||
Serial { port: String, baud_rate: u32 },
|
||||
|
|
|
@ -118,7 +118,7 @@ impl Controller {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn timeout_interval(&self) -> std::time::Duration {
|
||||
pub const fn timeout_interval(&self) -> std::time::Duration {
|
||||
self.interval
|
||||
}
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ impl Pli {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> eyre::Result<()> {
|
||||
fn flush(&self) -> eyre::Result<()> {
|
||||
self.port.clear(tokio_serial::ClearBuffer::All)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -286,9 +286,11 @@ impl Pli {
|
|||
}
|
||||
}
|
||||
|
||||
Err(last_err.unwrap_or(eyre::eyre!(
|
||||
"no error was stored in read_ram_with_retries: this should be unreachable??"
|
||||
)))
|
||||
Err(last_err.unwrap_or_else(|| {
|
||||
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>
|
||||
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ impl ChargeStateGauges {
|
|||
}
|
||||
}
|
||||
|
||||
fn zero_all(&mut self) {
|
||||
fn zero_all(&self) {
|
||||
self.start.set(0);
|
||||
self.night_check.set(0);
|
||||
self.disconnect.set(0);
|
||||
|
@ -230,7 +230,7 @@ impl ChargeStateGauges {
|
|||
self.unknown.set(0);
|
||||
}
|
||||
|
||||
fn set(&mut self, state: ChargeState) {
|
||||
fn set(&self, state: ChargeState) {
|
||||
match state {
|
||||
ChargeState::Start => {
|
||||
self.zero_all();
|
||||
|
|
|
@ -131,6 +131,8 @@ async fn watch(args: Args) -> eyre::Result<()> {
|
|||
primary.set_tx_to_secondary(follow_voltage_tx.clone());
|
||||
}
|
||||
|
||||
drop(config);
|
||||
|
||||
let controller_tasks = futures::stream::FuturesUnordered::new();
|
||||
for controller in controllers {
|
||||
controller_tasks.push(run_loop(controller));
|
||||
|
|
|
@ -87,7 +87,8 @@ async fn all_interfaces(
|
|||
let mut data = Vec::new();
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,10 +51,12 @@ impl Handler for UiStatic {
|
|||
data: v.contents().to_vec(),
|
||||
name: p,
|
||||
})
|
||||
.or(UI_DIR_FILES.get_file(&plus_index).map(|v| RawHtml {
|
||||
data: v.contents().to_vec(),
|
||||
name: plus_index,
|
||||
}));
|
||||
.or_else(|| {
|
||||
UI_DIR_FILES.get_file(&plus_index).map(|v| RawHtml {
|
||||
data: v.contents().to_vec(),
|
||||
name: plus_index,
|
||||
})
|
||||
});
|
||||
file.respond_to(req).or_forward((data, Status::NotFound))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue