TocCache

Trait TocCache 

Source
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§

Source

fn get_toc(&self, crc32: u32) -> Option<String>

Retrieves a cached TOC string based on the provided CRC32 checksum.

§Arguments
  • crc32 - The CRC32 checksum used to identify the TOC.
§Returns

An Option<String> containing the cached TOC if it exists, or None if not found.

Source

fn store_toc(&self, crc32: u32, toc: &str)

Stores a TOC string associated with the provided CRC32 checksum.

§Arguments
  • crc32 - The CRC32 checksum used to identify the TOC.
  • toc - The TOC string to be stored.

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.

Implementors§