diff --git a/egui/src/app.rs b/egui/src/app.rs index 1932d4fb..545fdd44 100644 --- a/egui/src/app.rs +++ b/egui/src/app.rs @@ -108,7 +108,7 @@ pub trait RepaintSignal: Send { /// On the web this is backed by [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). /// On desktop this is backed by the file system. pub trait Storage { - fn get_string(&self, key: &str) -> Option<&str>; + fn get_string(&self, key: &str) -> Option; fn set_string(&mut self, key: &str, value: String); /// write-to-disk or similar @@ -120,7 +120,7 @@ pub trait Storage { pub struct DummyStorage {} impl Storage for DummyStorage { - fn get_string(&self, _key: &str) -> Option<&str> { + fn get_string(&self, _key: &str) -> Option { None } fn set_string(&mut self, _key: &str, _value: String) {} @@ -131,7 +131,7 @@ impl Storage for DummyStorage { pub fn get_value(storage: &dyn Storage, key: &str) -> Option { storage .get_string(key) - .and_then(|value| serde_json::from_str(value).ok()) + .and_then(|value| serde_json::from_str(&value).ok()) } #[cfg(feature = "serde_json")] diff --git a/egui_glium/src/storage.rs b/egui_glium/src/storage.rs index fa2b43cf..55c57903 100644 --- a/egui_glium/src/storage.rs +++ b/egui_glium/src/storage.rs @@ -25,8 +25,8 @@ impl FileStorage { } impl egui::app::Storage for FileStorage { - fn get_string(&self, key: &str) -> Option<&str> { - self.kv.get(key).map(String::as_str) + fn get_string(&self, key: &str) -> Option { + self.kv.get(key).cloned() } fn set_string(&mut self, key: &str, value: String) { diff --git a/egui_web/src/lib.rs b/egui_web/src/lib.rs index ea30fa4a..7fa5bd6a 100644 --- a/egui_web/src/lib.rs +++ b/egui_web/src/lib.rs @@ -172,6 +172,20 @@ pub fn save_memory(ctx: &egui::Context) { } } +pub struct LocalStorage {} + +impl egui::app::Storage for LocalStorage { + fn get_string(&self, key: &str) -> Option { + local_storage_get(key) + } + fn set_string(&mut self, key: &str, value: String) { + local_storage_set(key, &value); + } + fn flush(&mut self) {} +} + +// ---------------------------------------------------------------------------- + pub fn handle_output(output: &egui::Output) { let egui::Output { cursor_icon,