docs.rs failed to build hyperchad_state-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
HyperChad State
A state management package for the HyperChad framework, providing in-memory caching with optional persistent storage backends.
Overview
hyperchad_state provides a StateStore that combines in-memory caching with pluggable persistence backends. Currently supports SQLite persistence and has provisions for iOS-specific storage.
What it provides
- StateStore - Main interface for get/set/remove operations
- StatePersistence - Trait for implementing custom persistence backends
- In-memory caching - Fast access using
BTreeMapwithRwLock - SQLite persistence - Store state in SQLite database
- Generic type support - Works with any
Serialize+DeserializeOwnedtypes - Async operations - All operations are async
Basic usage
use ;
use ;
async
StateStore API
set<T>(key, value) -> Result<(), Error>- Store a valueget<T>(key) -> Result<Option<T>, Error>- Retrieve a valueremove(key) -> Result<(), Error>- Remove a valuetake<T>(key) -> Result<Option<T>, Error>- Remove and return a valueclear() -> Result<(), Error>- Clear all values
Persistence backends
SQLite
// File-based database
let persistence = new.await?;
// In-memory database
let persistence = new_in_memory.await?;
Creates a state table with key and value columns.
Custom backends (StatePersistence)
StatePersistence is the public trait used by StateStore and is the main extension point for custom persistence implementations.
set<T>(key, value) -> Result<(), Error>get<T>(key) -> Result<Option<T>, Error>remove(key) -> Result<(), Error>take<T>(key) -> Result<Option<T>, Error>clear() -> Result<(), Error>
Features
default- Enablespersistence-iosandpersistence-sqlitepersistence-sqlite- Enable SQLite backendpersistence-ios- Enable iOS-specific persistence (stub)fail-on-warnings- Treat warnings as errors
Error types
Dependencies
switchy- Database abstraction (optional, for SQLite)serde- Serialization frameworkserde_json- JSON serializationasync-trait- Async trait supportthiserror- Error handlinglog- Loggingmoosicbox_assert- Assertion utilities