pub struct StateRegistry { /* private fields */ }Expand description
Central registry for widget state persistence.
The registry maintains an in-memory cache of widget states and delegates
to a StorageBackend for persistence. It provides the main API for
save/restore operations.
§Thread Safety
The registry is Send + Sync and uses internal locking for thread-safe access.
§Example
use ftui_runtime::state_persistence::{StateRegistry, MemoryStorage};
// Create registry with memory storage
let registry = StateRegistry::new(Box::new(MemoryStorage::new()));
// Load state for a widget
if let Some(entry) = registry.get("ScrollView::main") {
// Deserialize and restore...
}
// Save state
registry.set("ScrollView::main", 1, serialized_data);
registry.flush()?;Implementations§
Source§impl StateRegistry
impl StateRegistry
Sourcepub fn new(backend: Box<dyn StorageBackend>) -> Self
pub fn new(backend: Box<dyn StorageBackend>) -> Self
Create a new registry with the given storage backend.
Does not automatically load from storage; call load first.
Sourcepub fn load(&self) -> StorageResult<usize>
pub fn load(&self) -> StorageResult<usize>
Load all state from the storage backend.
This replaces the in-memory cache with stored data. Safe to call multiple times; later calls refresh the cache.
Sourcepub fn flush(&self) -> StorageResult<bool>
pub fn flush(&self) -> StorageResult<bool>
Flush dirty state to the storage backend.
Only writes if changes have been made since last flush.
Returns Ok(true) if data was written, Ok(false) if no changes.
Sourcepub fn get(&self, key: &str) -> Option<StoredEntry>
pub fn get(&self, key: &str) -> Option<StoredEntry>
Get a stored state entry by canonical key.
Returns None if no state exists for the key.
Sourcepub fn set(&self, key: impl Into<String>, version: u32, data: Vec<u8>)
pub fn set(&self, key: impl Into<String>, version: u32, data: Vec<u8>)
Set a state entry.
Marks the registry as dirty; call flush to persist.
Sourcepub fn remove(&self, key: &str) -> Option<StoredEntry>
pub fn remove(&self, key: &str) -> Option<StoredEntry>
Remove a state entry.
Returns the removed entry if it existed.
Sourcepub fn clear(&self) -> StorageResult<()>
pub fn clear(&self) -> StorageResult<()>
Clear all state from both cache and storage.
Sourcepub fn backend_name(&self) -> &str
pub fn backend_name(&self) -> &str
Get the backend name for logging.
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Check if the storage backend is available.
Source§impl StateRegistry
impl StateRegistry
Wrap in Arc for shared ownership.
Source§impl StateRegistry
impl StateRegistry
Sourcepub fn stats(&self) -> RegistryStats
pub fn stats(&self) -> RegistryStats
Get statistics about the registry.