pub trait SettingsRepository: Send + Sync {
// Required methods
fn load<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Settings, RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn save<'life0, 'life1, 'async_trait>(
&'life0 self,
settings: &'life1 Settings,
) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn modify<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
change: &'life1 SettingsChange<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Settings, CoreError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Repository for application settings persistence.
This trait defines operations for storing and retrieving the application settings as a whole. The implementation handles serialization.
§Design Rules
- No
sqlxtypes in signatures - Works with domain
Settingstype directly - Implementation handles JSON serialization internally
Required Methods§
Provided Methods§
Sourcefn modify<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
change: &'life1 SettingsChange<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Settings, CoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn modify<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
change: &'life1 SettingsChange<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Settings, CoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Read the stored settings, apply change to them, and store the
result, with no other write landing in between.
A partial update needs this. Read, change and save as three calls,
and a write that lands between the read and the save is overwritten
by a record read before it. Settings are written by more than one
process — the daemon, and gglib config settings set in a terminal —
so no lock held inside one of them can close that window.
The default makes exactly those three calls and holds nothing between them. It is right only for a store no other writer shares, such as an in-memory test double; a store another process writes overrides it.
§Errors
CoreError::Settings with whatever change refused, in which case
nothing is stored, or CoreError::Repository when the store fails.