emilk / emilk/egui

Feature request: allow setting storage values while initializing app

Open
#3,377 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

# Feature request: allow setting storage values while initializing app

**Is your feature request related to a problem? Please describe.**

I have a use-case where I need to save a value when starting a new game. However, `eframe` provides `&eframe::CreationContext` and only allows access to `&dyn Storage`, which means values can be loaded from storage but cannot be set.

**Describe the solution you'd like**

Replace `storage: Option<&dyn Storage>` with `storage: Option<&mut dyn Storage>` in `CreationContext`.

**Describe alternatives you've considered**

Currently, I get around the aforementioned limitation by adding a `start_time_to_save: Option` field to my state type and running

```rust
if let Some(start_time) = self.start_time_to_save.take() {
eframe::set_value(frame.storage_mut().unwrap(), START_TIME_KEY, &start_time);
}
```

every `update`.

Contributor guide

Open the contributing guide

Research direction

Start at eframe::CreationContext and trace how its storage reference is provided during app initialization. Review the existing frame.storage_mut() path and verify native and web initialization behavior; done means values can be written during creation without breaking existing storage reads or callers.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.