Expand description
§easy_prefs
A simple, safe, and performant preferences library for Rust applications.
Created by Ever Accountable – an app that helps people overcome compulsive porn use and become their best selves. Visit everaccountable.com for more details.
This library provides an intuitive API for managing preferences using a struct-like interface. Its key design goals are:
- Ease of Use: Read/write preferences as easily as struct fields.
- Safety: Uses temporary files for writes to prevent data corruption.
- Performance: Optimized for fast operations.
- Testability: Integrates seamlessly with unit tests.
Limitation: Not suited for large datasets. All data is held in memory, and the entire file is rewritten on save. For substantial data, use a database instead.
§Single-Instance Constraint
The load()
method enforces that only one instance of a preferences struct exists at a time,
using a static atomic flag. This prevents data races in production but can cause issues in
parallel test execution. Tests using load()
are combined into a single test to avoid conflicts.
§Error Handling
The load()
function returns a Result
with LoadError
variants instead of panicking.
Errors include existing instances, directory issues, or file operation failures. See
load()
for details.
Re-exports§
Macros§
- easy_
prefs - Macro to define a preferences struct with file persistence.
Structs§
- Test
Easy Preferences Updated - Updated test preferences for schema evolution.
Enums§
- Load
Error - Errors that can occur when loading preferences.