diff --git a/src/storage.rs b/src/storage.rs index 6546269..ddc665b 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,4 +1,5 @@ use core::any::Any; +use core::ffi::CStr; use core::fmt::{self, Debug}; use serde::de::DeserializeOwned; @@ -132,6 +133,23 @@ where } } +pub trait StorageIterate { + type Error: Debug; + type Entry: StorageEntry; + type Entries<'a>: Iterator> + where + Self: 'a; + + fn entries(&self) -> Result, Self::Error>; +} + +pub trait StorageEntry { + fn name_cstr(&self) -> &CStr; + fn name(&self) -> Option<&str> { + self.name_cstr().to_str().ok() + } +} + #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum StorageError { @@ -264,6 +282,21 @@ where } } +impl StorageIterate for StorageImpl +where + S: SerDe, + R: StorageIterate, +{ + type Error = R::Error; + type Entry = R::Entry; + type Entries<'a> = R::Entries<'a> + where Self: 'a; + + fn entries<'a>(&'a self) -> Result, Self::Error> { + self.raw_storage.entries() + } +} + struct Entry<'a> { name: &'a str, value: &'a dyn Any,