Persistent-Map: Effortless Persistent, Async Key-Value Store for Rust
Persistent-Map offers a simple and efficient way to store and retrieve key-value data that needs to survive application restarts. It provides an easy-to-use API with an asynchronous interface and pluggable storage backends.
Key Features
- Simple API: Familiar
insertandgetoperations with an async interface. - Multiple Backends: SQLite, CSV, in-memory, and extensible for more.
- Asynchronous: Designed with
async/awaitfor non-blocking operations. - In-Memory Cache: Uses
DashMapfor fast concurrent access to frequently used data. - Generic: Works with types that implement
SerializeandDeserializeOwned. - Flexible: Choose the storage backend that best fits your needs.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0" # Replace with the latest version
= { = "1", = ["macros", "rt-multi-thread"] } # For the async runtime
# Choose the backends you need
= { = "0.1.0", = ["sqlite", "csv_backend", "in_memory"] }
By default, the crate includes the SQLite and in-memory backends. You can enable other backends as needed.
Basic Usage
Here's a simple example using the SQLite backend:
use ;
async
Available Backends
SQLite Backend
The SQLite backend is ideal for most applications, providing reliable persistence with good performance.
use ;
async
CSV Backend
The CSV backend stores data in a simple CSV file, which can be useful for data that needs to be human-readable.
use ;
async
In-Memory Backend
The in-memory backend doesn't provide persistence but can be useful for testing or temporary storage.
use ;
async
Custom Backends
You can implement your own storage backend by implementing the StorageBackend trait:
use ;
use HashMap;
use ;
use Hash;
Performance Considerations
- The in-memory
DashMapprovides fast concurrent access to data - Persistence operations are asynchronous and don't block the main thread
- For best performance with frequent writes, consider calling
flush()periodically rather than after every write
Future Enhancements
- Additional storage backends (Postgres, Redis, etc.)
- Transactional operations
- Batch operations for improved performance
- Iterator support for more idiomatic Rust usage
Contributing
Contributions are welcome! Here are some ways you can contribute:
- Implement new storage backends
- Improve documentation
- Add tests
- Report bugs
- Suggest new features
Please open an issue or submit a pull request on GitHub.
Versioning
This project follows Semantic Versioning. The current version is 0.1.0, which means it is still in initial development and the API may change.
License
This project is licensed under the MIT License - see the LICENSE file for details.