From 4bfd7a28b6d42a6cb6f94b8bc3a1a3fd2459965d Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Mon, 25 Aug 2025 02:47:56 -0700 Subject: [PATCH] Mark various enums/structs as `#[non_exhaustive]` (#3981) * Mark various enums/structs as `#[non_exhaustive]` * Update `CHANGELOG.md` --- esp-radio/CHANGELOG.md | 2 ++ esp-radio/src/wifi/mod.rs | 24 ++++++++++++++++-------- esp-radio/src/wifi/state.rs | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/esp-radio/CHANGELOG.md b/esp-radio/CHANGELOG.md index f5be6811b..b2b845ed9 100644 --- a/esp-radio/CHANGELOG.md +++ b/esp-radio/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `esp-ieee802154` package has been folded into `esp-radio`, it's now alloc. (#3861, #3890) - `ble`, `esp-now`, `csi`, `sniffer`, `esp-ieee802154` and `smoltcp` features and APIs marked as unstable (#3865) - Update bt-hci version to add additional HCI commands (#3920) +- A number of enums/structs have been marked as `#[non_exhaustive]` (#3981) + - `AuthMethod`, `Protocol`, `AccessPointInfo`, `AccessPointConfiguration`, `ClientConfiguration`, `Capability`, `Configuration`, `WifiEvent`, `InternalWifiError`, `ScanTypeConfig`, and `WifiState` ### Fixed diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 369ab657b..5392b6479 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -149,10 +149,10 @@ use crate::binary::{ }; /// Supported Wi-Fi authentication methods. -#[derive(EnumSetType, Debug, PartialOrd)] +#[derive(Debug, Default, PartialOrd, EnumSetType)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Default)] +#[non_exhaustive] pub enum AuthMethod { /// No authentication (open network). None, @@ -184,10 +184,10 @@ pub enum AuthMethod { } /// Supported Wi-Fi protocols. -#[derive(EnumSetType, Debug, PartialOrd)] +#[derive(Debug, Default, PartialOrd, EnumSetType)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Default)] +#[non_exhaustive] pub enum Protocol { /// 802.11b protocol. P802D11B, @@ -274,6 +274,7 @@ impl defmt::Format for Country { #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[non_exhaustive] pub struct AccessPointInfo { /// The SSID of the access point. // TODO: we can use the `alloc` feature once we have `defmt` 1.0.2 @@ -302,6 +303,7 @@ pub struct AccessPointInfo { /// Configuration for a Wi-Fi access point. #[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[non_exhaustive] pub struct AccessPointConfiguration { /// The SSID of the access point. pub ssid: String, @@ -419,6 +421,7 @@ impl defmt::Format for AccessPointConfiguration { /// Client configuration for a Wi-Fi connection. #[derive(Clone, PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[non_exhaustive] pub struct ClientConfiguration { /// The SSID of the Wi-Fi network. pub ssid: String, @@ -713,6 +716,7 @@ impl Default for EapClientConfiguration { #[derive(EnumSetType, Debug, PartialOrd)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[non_exhaustive] pub enum Capability { /// The device operates as a client, connecting to an existing network. Client, @@ -727,10 +731,11 @@ pub enum Capability { } /// Configuration of Wi-Fi operation mode. +#[allow(clippy::large_enum_variant)] #[derive(Clone, Debug, PartialEq, Eq, Default)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[allow(clippy::large_enum_variant)] +#[non_exhaustive] pub enum Configuration { /// No configuration (default). #[default] @@ -1204,9 +1209,10 @@ pub enum WifiError { } /// Events generated by the WiFi driver. -#[repr(i32)] #[derive(Debug, FromPrimitive, EnumSetType)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[non_exhaustive] +#[repr(i32)] pub enum WifiEvent { /// Wi-Fi is ready for operation. WifiReady = 0, @@ -1311,9 +1317,10 @@ pub enum WifiEvent { } /// Error originating from the underlying drivers -#[repr(i32)] #[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[non_exhaustive] +#[repr(i32)] pub enum InternalWifiError { /// Out of memory NoMem = 0x101, @@ -1589,7 +1596,8 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> { /// |--------------------------------------|------------|-------------| /// | **Power consumption** | High | Low | /// | **Time required (typical behavior)** | Low | High | -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[non_exhaustive] pub enum ScanTypeConfig { /// Active scan with min and max scan time per channel. This is the default /// and recommended if you are unsure. diff --git a/esp-radio/src/wifi/state.rs b/esp-radio/src/wifi/state.rs index d633dc4a2..07962ea1b 100644 --- a/esp-radio/src/wifi/state.rs +++ b/esp-radio/src/wifi/state.rs @@ -8,6 +8,7 @@ use super::WifiEvent; #[atomic_enum] #[derive(PartialEq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[non_exhaustive] pub enum WifiState { /// Station started. StaStarted,