diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1,9 +1,11 @@ | |||
1 | pub use directories::ProjectDirs; | 1 | pub use directories::{ProjectDirs, UserDirs}; |
2 | pub use serde::{de::DeserializeOwned, Serialize}; | 2 | pub use serde::{de::DeserializeOwned, Serialize}; |
3 | pub use serde_json; | 3 | pub use serde_json; |
4 | pub use serde_yaml; | 4 | pub use serde_yaml; |
5 | pub use toml; | 5 | pub use toml; |
6 | 6 | ||
7 | use std::path::{Path, PathBuf}; | ||
8 | |||
7 | #[derive(Debug)] | 9 | #[derive(Debug)] |
8 | pub enum FondantError { | 10 | pub enum FondantError { |
9 | InvalidHomeDir, | 11 | InvalidHomeDir, |
@@ -15,6 +17,20 @@ pub enum FondantError { | |||
15 | FileOpenError, | 17 | FileOpenError, |
16 | } | 18 | } |
17 | 19 | ||
20 | pub fn expand_tilde<P: AsRef<Path>>(path: P) -> PathBuf { | ||
21 | let p = path.as_ref(); | ||
22 | if p.starts_with("~") { | ||
23 | if p == Path::new("~") { | ||
24 | return UserDirs::new().unwrap().home_dir().to_path_buf(); | ||
25 | } else { | ||
26 | let mut h = UserDirs::new().unwrap().home_dir().to_path_buf(); | ||
27 | h.push(p.strip_prefix("~/").unwrap()); | ||
28 | return h; | ||
29 | } | ||
30 | } | ||
31 | return p.to_path_buf(); | ||
32 | } | ||
33 | |||
18 | pub trait Configure: Serialize + DeserializeOwned + Default { | 34 | pub trait Configure: Serialize + DeserializeOwned + Default { |
19 | fn load() -> Result<Self, FondantError>; | 35 | fn load() -> Result<Self, FondantError>; |
20 | fn store(&self) -> Result<(), FondantError>; | 36 | fn store(&self) -> Result<(), FondantError>; |