Skip to content

Commit b5878a8

Browse files
committed
add defmt attributes for caches
1 parent 855f3cf commit b5878a8

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

src/cache/key_pointers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) trait KeyPointersCache<KEY: Key> {
1212
}
1313

1414
#[derive(Debug)]
15+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
1516
pub(crate) struct CachedKeyPointers<KEY: Eq, const KEYS: usize> {
1617
key_pointers: [Option<(KEY, NonZeroU32)>; KEYS],
1718
}
@@ -77,6 +78,7 @@ impl<KEY: Key, const KEYS: usize> KeyPointersCache<KEY> for CachedKeyPointers<KE
7778
}
7879

7980
#[derive(Debug)]
81+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
8082
pub(crate) struct UncachedKeyPointers;
8183

8284
impl<KEY: Key> KeyPointersCache<KEY> for UncachedKeyPointers {

src/cache/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl<KEY: Key, T: PrivateKeyCacheImpl<KEY>> PrivateKeyCacheImpl<KEY> for &mut T
164164
}
165165

166166
#[derive(Debug)]
167+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
167168
pub(crate) struct DirtTracker {
168169
/// Managed from the library code.
169170
///
@@ -198,6 +199,7 @@ impl DirtTracker {
198199
/// This type of cache doesn't have to be kept around and may be constructed on every api call.
199200
/// You could simply pass `&mut NoCache::new()` every time.
200201
#[derive(Debug)]
202+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
201203
pub struct NoCache {
202204
page_states: UncachedPageStates,
203205
page_pointers: UncachedPagePointers,
@@ -266,6 +268,7 @@ impl<KEY: Key> PrivateKeyCacheImpl<KEY> for NoCache {
266268
///
267269
/// Make sure the page count is correct. If the number is lower than the actual amount, the code will panic at some point.
268270
#[derive(Debug)]
271+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
269272
pub struct PageStateCache<const PAGE_COUNT: usize> {
270273
dirt_tracker: DirtTracker,
271274
page_states: CachedPageStates<PAGE_COUNT>,
@@ -339,6 +342,7 @@ impl<KEY: Key, const PAGE_COUNT: usize> PrivateKeyCacheImpl<KEY> for PageStateCa
339342
///
340343
/// Make sure the page count is correct. If the number is lower than the actual amount, the code will panic at some point.
341344
#[derive(Debug)]
345+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
342346
pub struct PagePointerCache<const PAGE_COUNT: usize> {
343347
dirt_tracker: DirtTracker,
344348
page_states: CachedPageStates<PAGE_COUNT>,
@@ -417,6 +421,7 @@ impl<KEY: Key, const PAGE_COUNT: usize> PrivateKeyCacheImpl<KEY> for PagePointer
417421
/// the chance of a cache hit.
418422
/// The keys are cached in a fifo and any time its location is updated in cache it's added to the front.
419423
#[derive(Debug)]
424+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
420425
pub struct KeyPointerCache<const PAGE_COUNT: usize, KEY: Key, const KEYS: usize> {
421426
dirt_tracker: DirtTracker,
422427
page_states: CachedPageStates<PAGE_COUNT>,

src/cache/page_pointers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub(crate) trait PagePointersCache: Debug {
2929

3030
// Use NoneZeroU32 because we never store 0's in here (because of the first page marker)
3131
// and so Option can make use of the niche so we save bytes
32+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
3233
pub(crate) struct CachedPagePointers<const PAGE_COUNT: usize> {
3334
after_erased_pointers: [Option<NonZeroU32>; PAGE_COUNT],
3435
after_written_pointers: [Option<NonZeroU32>; PAGE_COUNT],
@@ -138,6 +139,7 @@ impl<const PAGE_COUNT: usize> PagePointersCache for CachedPagePointers<PAGE_COUN
138139
}
139140

140141
#[derive(Debug, Default)]
142+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
141143
pub(crate) struct UncachedPagePointers;
142144

143145
impl PagePointersCache for UncachedPagePointers {

src/cache/page_states.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) trait PageStatesCache: Debug {
88
fn invalidate_cache_state(&mut self);
99
}
1010

11+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
1112
pub(crate) struct CachedPageStates<const PAGE_COUNT: usize> {
1213
pages: [Option<PageState>; PAGE_COUNT],
1314
}
@@ -55,6 +56,7 @@ impl<const PAGE_COUNT: usize> PageStatesCache for CachedPageStates<PAGE_COUNT> {
5556
}
5657

5758
#[derive(Debug, Default)]
59+
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
5860
pub(crate) struct UncachedPageStates;
5961

6062
impl PageStatesCache for UncachedPageStates {

0 commit comments

Comments
 (0)