Add Support for Custom Storage Backends in eframe via a New NativeOptions Field
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
Problem: Currently, eframe only supports saving app state using RON files. This limitation restricts developers who wish to integrate with different storage systems like SQLite or handle deserialization themselves for alternative data formats.
Solution: Introduce a customization option that allows users to provide a custom storage mechanism. This could be achieved by accepting a closure or function during initialization, enabling dynamic storage creation (e.g., SQLite, PostgreSQL).
https://github.com/emilk/egui/blob/0db56dc9f1a8459b5b9376159fab7d7048b19b65/crates/eframe/src/native/glow_integration.rs#L193-L209
https://github.com/emilk/egui/blob/0db56dc9f1a8459b5b9376159fab7d7048b19b65/crates/eframe/src/native/epi_integration.rs#L130-L147
Proposed Implementation: Modify eframe to accept a `Box Box>` as an optional parameter in the initialization process. This closure would allow developers to return their own custom storage implementation instead of the default FileStorage.
Examples:
```Rust
pub struct NativeOptions {
// ... other fields ...
pub persistence_path: Option,
/// Override the default storage creation with your own custom storage implementation
pub storage_creator: Option Option>>>,
}
```
```Rust
fn init_run_state(
&mut self,
event_loop: &ActiveEventLoop,
) -> Result<&mut GlowWinitRunning<'app>> {
profiling::function_scope!();
let storage = if let Some(storage_creator) = &self.native_options.storage_creator {
storage_creator()
} else if let Some(file) = &self.native_options.persistence_path {
epi_integration::create_storage_with_file(file)
} else {
epi_integration::create_storage(
self.native_options
.viewport
.app_id
.as_ref()
.unwrap_or(&self.app_name),
)
};
// ... rest of function
}
```
Contributor guide
Research direction
Read the storage initialization paths in crates/eframe/src/native/glow_integration.rs and crates/eframe/src/native/epi_integration.rs, especially init_run_state and the referenced creation functions. Confirm how NativeOptions is constructed and how epi::Storage is used. Done means a custom storage creator can override the default FileStorage while existing persistence_path and default behavior remain available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100