diff --git a/demo_glium/src/main.rs b/demo_glium/src/main.rs index 721c8e9a..cf13eaa6 100644 --- a/demo_glium/src/main.rs +++ b/demo_glium/src/main.rs @@ -6,7 +6,7 @@ fn main() { let title = "Egui glium demo"; // Persist app state to file: - let storage = egui_glium::storage::FileStorage::from_path(".egui_demo_glium.json".into()); + let storage = egui_glium::storage::FileStorage::from_path(".egui_demo_glium.json"); // Alternative: store nowhere // let storage = egui::app::DummyStorage::default(); diff --git a/egui_glium/CHANGELOG.md b/egui_glium/CHANGELOG.md index 66c8b87d..8d6a6d02 100644 --- a/egui_glium/CHANGELOG.md +++ b/egui_glium/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Changed + +* FileStorage::from_path now takes `Into` instead of `String` + ## 0.4.0 - 2020-11-28 Started changelog. Features: diff --git a/egui_glium/src/storage.rs b/egui_glium/src/storage.rs index 0a99bc8f..77d86f98 100644 --- a/egui_glium/src/storage.rs +++ b/egui_glium/src/storage.rs @@ -1,17 +1,21 @@ -use std::collections::HashMap; +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; // ---------------------------------------------------------------------------- /// A key-value store backed by a JSON file on disk. /// Used to restore egui state, glium window position/size and app state. pub struct FileStorage { - path: String, + path: PathBuf, kv: HashMap, dirty: bool, } impl FileStorage { - pub fn from_path(path: String) -> Self { + pub fn from_path(path: impl Into) -> Self { + let path: PathBuf = path.into(); Self { kv: read_json(&path).unwrap_or_default(), path, @@ -42,7 +46,7 @@ impl egui::app::Storage for FileStorage { // ---------------------------------------------------------------------------- -pub fn read_json(memory_json_path: impl AsRef) -> Option +pub fn read_json(memory_json_path: impl AsRef) -> Option where T: serde::de::DeserializeOwned, { diff --git a/example_glium/.gitignore b/example_glium/.gitignore new file mode 100644 index 00000000..0cb09d2b --- /dev/null +++ b/example_glium/.gitignore @@ -0,0 +1 @@ +.egui_example_glium.json diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index a3a00d10..2b8a72fc 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -10,7 +10,7 @@ fn main() { let title = "My Egui Window"; // Persist app state to file: - let storage = egui_glium::storage::FileStorage::from_path(".egui_example_glium.json".into()); + let storage = egui_glium::storage::FileStorage::from_path(".egui_example_glium.json"); // Alternative: store nowhere // let storage = egui::app::DummyStorage::default();