From edb42b4f227319f712d107a63a75cddd41839429 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 25 Mar 2020 20:20:23 +0530 Subject: ignore nested `target`s --- fondant_deps/Cargo.toml | 19 +++++++++++++++++++ fondant_deps/src/lib.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 fondant_deps/Cargo.toml create mode 100644 fondant_deps/src/lib.rs (limited to 'fondant_deps') diff --git a/fondant_deps/Cargo.toml b/fondant_deps/Cargo.toml new file mode 100644 index 0000000..2d1a2db --- /dev/null +++ b/fondant_deps/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "fondant_deps" +version = "0.1.0" +authors = ["Akshay "] +edition = "2018" + +[dependencies] +toml = "^0.5" +serde_yaml = "0.8" +serde_json = "1.0.48" +directories = "2.0" + +[dependencies.serde] +version = "1.0.103" +features = ["derive"] + +[dependencies.syn] +version = "1.0" +features = ["full"] diff --git a/fondant_deps/src/lib.rs b/fondant_deps/src/lib.rs new file mode 100644 index 0000000..6f62ce8 --- /dev/null +++ b/fondant_deps/src/lib.rs @@ -0,0 +1,47 @@ +pub mod fondant_exports { + pub use directories::{ProjectDirs, UserDirs}; + pub use serde::{de::DeserializeOwned, Serialize}; + pub use serde_json; + pub use serde_yaml; + use std::path::{Path, PathBuf}; + pub use toml; + pub fn expand_tilde>(path: P) -> PathBuf { + let p = path.as_ref(); + if p.starts_with("~") { + if p == Path::new("~") { + return UserDirs::new().unwrap().home_dir().to_path_buf(); + } else { + let mut h = UserDirs::new().unwrap().home_dir().to_path_buf(); + h.push(p.strip_prefix("~/").unwrap()); + return h; + } + } + return p.to_path_buf(); + } +} + +use serde::{de::DeserializeOwned, Serialize}; +#[derive(Debug)] +/// Errors that `load` and `store` can result in +pub enum FondantError { + /// Occurs when the home dir is not accessible. + /// You should probably `panic!` when this is thrown. + InvalidHomeDir, + + /// Invalid toml/yaml/json config. + ConfigParseError, + + /// Invalid permissions to create config dir. + /// Might occur when you set config dir to, say, `/etc/config.toml` and run without superuser. + DirCreateErr(std::io::Error), + LoadError, + FileWriteError, + FileReadError, + FileOpenError, +} + +/// Derive this trait on a struct to mark it as a 'configuration' struct. +pub trait Configure: Serialize + DeserializeOwned + Default { + fn load() -> Result; + fn store(&self) -> Result<(), FondantError>; +} -- cgit v1.2.3