refactor: use IntEnum instead of a custom implementation for ConfigKey in config.rs

This commit is contained in:
2026-08-17 21:14:00 -05:00
parent 69669f2011
commit d70b35dd92
3 changed files with 28 additions and 19 deletions
+2 -19
View File
@@ -4,6 +4,7 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embedded_rpc::RpcService;
use esp_hal::peripherals::FLASH;
use esp_storage::FlashStorage;
use int_enum::IntEnum;
use sequential_storage::{
cache::Cache,
map::{Key, MapConfig, MapStorage, SerializationError},
@@ -52,30 +53,12 @@ async fn config_handler(flash: FLASH<'static>) {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, IntEnum)]
#[repr(u8)]
enum ConfigKey {
Wifi,
}
impl TryFrom<u8> for ConfigKey {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
const WIFI: u8 = ConfigKey::Wifi as u8;
match value {
WIFI => Ok(ConfigKey::Wifi),
_ => Err(()),
}
}
}
impl From<ConfigKey> for u8 {
fn from(c: ConfigKey) -> u8 {
c as u8
}
}
impl Key for ConfigKey {
fn get_len(_: &[u8]) -> Result<usize, SerializationError> {
Ok(1)