From 27a280536ee0592d454035de372e4b253f21feb9 Mon Sep 17 00:00:00 2001 From: Reed Krantz Date: Sat, 10 Oct 2026 18:28:34 -0500 Subject: [PATCH] fix: fix clippy warnings --- src/config.rs | 4 ++-- src/http_api.rs | 38 ++++++++++++++++++-------------------- src/lib.rs | 2 ++ src/wifi.rs | 26 +++++++++++++++----------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5e8348f..06210a6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -112,7 +112,7 @@ impl Key for ConfigKey { let val = buffer .get_mut(0) .ok_or(sequential_storage::map::SerializationError::BufferTooSmall)?; - *val = self.clone().into(); + *val = (*self).into(); Ok(1) } @@ -120,7 +120,7 @@ impl Key for ConfigKey { buffer: &[u8], ) -> Result<(Self, usize), sequential_storage::map::SerializationError> { let val = *buffer - .get(0) + .first() .ok_or(sequential_storage::map::SerializationError::BufferTooSmall)?; Ok(( val.try_into() diff --git a/src/http_api.rs b/src/http_api.rs index c99f55b..9e488c2 100644 --- a/src/http_api.rs +++ b/src/http_api.rs @@ -14,19 +14,30 @@ impl AppBuilder for HttpApiProps { } } +#[allow( + clippy::large_stack_frames, + reason = "it's not unusual to allocate larger objects in service's start functions" +)] pub fn start_http_api(spawner: Spawner, net_stack: Stack<'static>) { - spawner.spawn( - handler(HttpApiApp::new( + let service = crate::mk_static!( + HttpApiApp<'static, HttpApiProps>, + HttpApiApp { + config: Default::default(), + net_stack, - Default::default(), - Default::default(), - )) - .unwrap(), + app: HttpApiProps.build_app(), + + tcp_rx_buffer: [0; 1024], + tcp_tx_buffer: [0; 1024], + http_buffer: [0; 2048], + } ); + + spawner.spawn(handler(service).unwrap()); } #[embassy_executor::task] -async fn handler(mut service: HttpApiApp<'static, HttpApiProps>) { +async fn handler(service: &'static mut HttpApiApp<'static, HttpApiProps>) { service.run().await; } @@ -56,19 +67,6 @@ pub struct HttpApiApp<'a, AB: AppBuilder> { } impl<'a, AB: AppBuilder> HttpApiApp<'a, AB> { - pub fn new(net_stack: Stack<'a>, config: HttpApiConfig, app: AB) -> Self { - Self { - config: config, - - net_stack: net_stack, - app: app.build_app(), - - tcp_rx_buffer: [0; 1024], - tcp_tx_buffer: [0; 1024], - http_buffer: [0; 2048], - } - } - pub async fn run(&mut self) { picoserve::Server::new( &self.app, diff --git a/src/lib.rs b/src/lib.rs index b2b7c21..3e1feac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,8 @@ #![deny(clippy::large_stack_frames)] #![feature(impl_trait_in_assoc_type)] +extern crate alloc; + pub mod http_api; pub mod clock; diff --git a/src/wifi.rs b/src/wifi.rs index 0b9ac76..863187e 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -1,3 +1,4 @@ +use alloc::boxed::Box; use defmt::{error, info}; use embassy_executor::Spawner; use embassy_futures::select::{Either, select}; @@ -11,6 +12,10 @@ use esp_radio::wifi::sta::StationConfig; use esp_radio::wifi::{ControllerConfig, Interface, WifiController}; use oneshot::{RecvError, Sender}; +#[allow( + clippy::large_stack_frames, + reason = "it's not unusual to allocate larger objects in service's start functions" +)] pub fn start_wifi(spawner: Spawner, wifi: WIFI<'static>) -> Stack<'static> { let wifi_config = esp_radio::wifi::Config::Station(StationConfig::default()); @@ -45,7 +50,7 @@ pub fn start_wifi(spawner: Spawner, wifi: WIFI<'static>) -> Stack<'static> { net_stack } -pub async fn set_station_config(config: esp_radio::wifi::Config) -> Result<(), RecvError> { +pub async fn set_station_config(config: Box) -> Result<(), RecvError> { let (send, recv) = oneshot::channel(); WIFI_CHANNEL .send(WifiOperationMessage::SetStationConfig(config, send)) @@ -53,7 +58,7 @@ pub async fn set_station_config(config: esp_radio::wifi::Config) -> Result<(), R recv.await } -pub async fn set_dhcp_config(config: embassy_net::DhcpConfig) -> Result<(), RecvError> { +pub async fn set_dhcp_config(config: Box) -> Result<(), RecvError> { let (send, recv) = oneshot::channel(); WIFI_CHANNEL .send(WifiOperationMessage::SetDhcpConfig(config, send)) @@ -64,8 +69,8 @@ pub async fn set_dhcp_config(config: embassy_net::DhcpConfig) -> Result<(), Recv static WIFI_CHANNEL: Channel = Channel::new(); enum WifiOperationMessage { - SetStationConfig(esp_radio::wifi::Config, Sender<()>), - SetDhcpConfig(embassy_net::DhcpConfig, Sender<()>), + SetStationConfig(Box, Sender<()>), + SetDhcpConfig(Box, Sender<()>), } #[embassy_executor::task] @@ -73,15 +78,15 @@ async fn handler(net_stack: Stack<'static>) -> ! { loop { match WIFI_CHANNEL.receive().await { WifiOperationMessage::SetStationConfig(config, resp) => { - WIFI_HANDLER_RPC.signal(config); - if let Err(_) = resp.send(()) { + WIFI_HANDLER_RPC.signal(*config); + if resp.send(()).is_err() { // TODO: find a way to not hard-code symbols in a string error!("WifiOperationMessage::SetStationConfig failed to respond") }; } WifiOperationMessage::SetDhcpConfig(config, resp) => { - net_stack.set_config_v4(embassy_net::ConfigV4::Dhcp(config)); - if let Err(_) = resp.send(()) { + net_stack.set_config_v4(embassy_net::ConfigV4::Dhcp(*config)); + if resp.send(()).is_err() { // TODO: find a way to not hard-code symbols in a string error!("WifiOperationMessage::SetDhcpConfig failed to respond") }; @@ -114,10 +119,9 @@ async fn connection_handler(mut controller: WifiController<'static>) -> ! { loop { if let Either::First(req) = select(WIFI_HANDLER_RPC.wait(), connection(&mut controller)).await + && let Some(err) = controller.set_config(&req).err() { - if let Some(err) = controller.set_config(&req).err() { - error!("Wifi controller failed to set a new config: {:?}", err) - } + error!("Wifi controller failed to set a new config: {:?}", err) } } }