diff options
author | Daniel <kingdread@gmx.de> | 2020-05-03 17:34:28 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-05-03 17:34:28 +0200 |
commit | 18544e32ecd1d3bc3535214f0c2edca38346e3a5 (patch) | |
tree | 3334b84a9bb014dcf5ffc768148ecd295afb78b2 /src/guilds.rs | |
parent | 913bc8c547e97a785cf1cd9fc20f8377f898da2c (diff) | |
download | raidgrep-18544e32ecd1d3bc3535214f0c2edca38346e3a5.tar.gz raidgrep-18544e32ecd1d3bc3535214f0c2edca38346e3a5.tar.bz2 raidgrep-18544e32ecd1d3bc3535214f0c2edca38346e3a5.zip |
save REPL history to a file
This persists the REPL history across program restarts.
The code should probably be cleaned up a bit more, the error handling in
this one is a bit all over the place. This is because we don't want to
make it a hard error in case the history cannot be saved.
Diffstat (limited to 'src/guilds.rs')
-rw-r--r-- | src/guilds.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/guilds.rs b/src/guilds.rs index 0eff6ad..24ec817 100644 --- a/src/guilds.rs +++ b/src/guilds.rs @@ -1,7 +1,8 @@ //! Guild name retrieval and caching functions. +use super::paths; + use std::collections::HashMap; use std::fs::File; -use std::path::PathBuf; use std::sync::RwLock; use once_cell::sync::Lazy; @@ -52,15 +53,9 @@ pub fn lookup(api_id: &str) -> Option<Guild> { Some(guild) } -fn cache_path() -> PathBuf { - let mut cache_path = dirs::cache_dir().unwrap(); - cache_path.push("raidgrep"); - cache_path -} - /// Loads the cache from the file system. pub fn prepare_cache() { - let path = cache_path(); + let path = paths::cache_path(); if !path.is_file() { return; } @@ -73,7 +68,7 @@ pub fn prepare_cache() { /// Saves the cache to the file system pub fn save_cache() { - let path = cache_path(); + let path = paths::cache_path(); let file = File::create(path).expect("Cannot open cache for writing"); serde_json::to_writer(file, &*CACHE.read().unwrap()).unwrap(); } |