aboutsummaryrefslogtreecommitdiff
path: root/fondant_deps
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-03-25 14:50:23 +0000
committerAkshay <[email protected]>2020-03-25 14:50:23 +0000
commitedb42b4f227319f712d107a63a75cddd41839429 (patch)
tree082fc9cd4828d108052151102546a2904e35d730 /fondant_deps
parent095948f8b92d590b2e2b66f44d9434577952577d (diff)
ignore nested `target`s
Diffstat (limited to 'fondant_deps')
-rw-r--r--fondant_deps/Cargo.toml19
-rw-r--r--fondant_deps/src/lib.rs47
2 files changed, 66 insertions, 0 deletions
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 @@
1[package]
2name = "fondant_deps"
3version = "0.1.0"
4authors = ["Akshay <[email protected]>"]
5edition = "2018"
6
7[dependencies]
8toml = "^0.5"
9serde_yaml = "0.8"
10serde_json = "1.0.48"
11directories = "2.0"
12
13[dependencies.serde]
14version = "1.0.103"
15features = ["derive"]
16
17[dependencies.syn]
18version = "1.0"
19features = ["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 @@
1pub mod fondant_exports {
2 pub use directories::{ProjectDirs, UserDirs};
3 pub use serde::{de::DeserializeOwned, Serialize};
4 pub use serde_json;
5 pub use serde_yaml;
6 use std::path::{Path, PathBuf};
7 pub use toml;
8 pub fn expand_tilde<P: AsRef<Path>>(path: P) -> PathBuf {
9 let p = path.as_ref();
10 if p.starts_with("~") {
11 if p == Path::new("~") {
12 return UserDirs::new().unwrap().home_dir().to_path_buf();
13 } else {
14 let mut h = UserDirs::new().unwrap().home_dir().to_path_buf();
15 h.push(p.strip_prefix("~/").unwrap());
16 return h;
17 }
18 }
19 return p.to_path_buf();
20 }
21}
22
23use serde::{de::DeserializeOwned, Serialize};
24#[derive(Debug)]
25/// Errors that `load` and `store` can result in
26pub enum FondantError {
27 /// Occurs when the home dir is not accessible.
28 /// You should probably `panic!` when this is thrown.
29 InvalidHomeDir,
30
31 /// Invalid toml/yaml/json config.
32 ConfigParseError,
33
34 /// Invalid permissions to create config dir.
35 /// Might occur when you set config dir to, say, `/etc/config.toml` and run without superuser.
36 DirCreateErr(std::io::Error),
37 LoadError,
38 FileWriteError,
39 FileReadError,
40 FileOpenError,
41}
42
43/// Derive this trait on a struct to mark it as a 'configuration' struct.
44pub trait Configure: Serialize + DeserializeOwned + Default {
45 fn load() -> Result<Self, FondantError>;
46 fn store(&self) -> Result<(), FondantError>;
47}