pub trait TocCache:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn get_toc(&self, crc32: u32) -> Option<String>;
fn store_toc(&self, crc32: u32, toc: &str);
}Expand description
A trait for caching Table of Contents (TOC) data.
This trait provides methods for storing and retrieving TOC information using a CRC32 checksum as the key. Implementations can use this to avoid re-fetching TOC data when the checksum matches a cached version.
§Concurrency
Both methods take &self to allow concurrent reads during parallel TOC fetching
(Log and Param subsystems fetch their TOCs simultaneously). Implementations should
use interior mutability (e.g., RwLock) for thread-safe caching.
§Example
use std::sync::{Arc, RwLock};
use std::collections::HashMap;
use crazyflie_lib::TocCache;
#[derive(Clone)]
struct InMemoryCache {
data: Arc<RwLock<HashMap<u32, String>>>,
}
impl TocCache for InMemoryCache {
fn get_toc(&self, crc32: u32) -> Option<String> {
self.data.read().ok()?.get(&crc32).cloned()
}
fn store_toc(&self, crc32: u32, toc: &str) {
if let Ok(mut lock) = self.data.write() {
lock.insert(crc32, toc.to_string());
}
}
}Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.