aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-03-15 16:23:46 +0000
committerAkshay <[email protected]>2020-03-15 16:23:46 +0000
commite37ff7725a37854be50c06693cc0f71e72847f19 (patch)
treeff8dea5df6f094a9adb507f8c3626fca2d43037a /src
parentb080112c6ce1d969710bef1bd536d6a2f9146a50 (diff)
split into lib and macros crates
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs70
1 files changed, 18 insertions, 52 deletions
diff --git a/src/lib.rs b/src/lib.rs
index bd6ed2b..78c3ffb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,57 +1,23 @@
1extern crate proc_macro;
2
3use std::path::{Path, PathBuf}; 1use std::path::{Path, PathBuf};
4 2
5use proc_macro::TokenStream; 3pub use serde::{de::DeserializeOwned, Serialize};
6use quote::quote; 4pub use directories::ProjectDirs;
7use syn::{parse_macro_input, AttrStyle, Attribute, DeriveInput, Lit, Meta, MetaNameValue}; 5pub use toml;
8 6pub use serde_json;
9use serde::{de::DeserializeOwned, Serialize}; 7pub use serde_yaml;
10 8
11trait Config<T> 9#[derive(Debug)]
12where 10pub enum FondantError {
13 T: Serialize + DeserializeOwned + Default, 11 InvalidHomeDir,
14{ 12 ConfigParseError,
15 fn load() -> Result<T, String>; 13 DirCreateErr(std::io::Error),
16 fn store() -> Result<(), String>; 14 LoadError,
17} 15 FileWriteError,
18 16 FileReadError,
19fn is_outer_attribute(a: &Attribute) -> bool { 17 FileOpenError,
20 match a.style {
21 AttrStyle::Outer => true,
22 _ => false,
23 }
24} 18}
25 19
26#[proc_macro_derive(Config, attributes(filename, filetype))] 20pub trait Config: Serialize + DeserializeOwned + Default {
27pub fn config_attribute(item: TokenStream) -> TokenStream { 21 fn load() -> Result<Self, FondantError>;
28 let mut ast: DeriveInput = syn::parse(item).unwrap(); 22 fn store(&self) -> Result<(), FondantError>;
29
30 let mut filename: Option<PathBuf> = None;
31 let mut filetype: Option<PathBuf> = None;
32
33 for option in ast.attrs.into_iter() {
34 let option = option.parse_meta().unwrap();
35 match option {
36 Meta::NameValue(MetaNameValue {
37 ref path, ref lit, ..
38 }) if path.is_ident("filename") => {
39 if let Lit::Str(f) = lit {
40 filename = Some(PathBuf::from(f.value()));
41 }
42 }
43 Meta::NameValue(MetaNameValue {
44 ref path, ref lit, ..
45 }) if path.is_ident("filetype") => {
46 if let Lit::Str(f) = lit {
47 filetype = Some(PathBuf::from(f.value()));
48 }
49 }
50 _ => {}
51 }
52 }
53
54 println!("{:?} {:?}", filename, filetype);
55
56 TokenStream::new()
57} 23}