From 18544e32ecd1d3bc3535214f0c2edca38346e3a5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 3 May 2020 17:34:28 +0200 Subject: 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. --- src/guilds.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/guilds.rs') 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 { 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(); } -- cgit v1.2.3