From e37ff7725a37854be50c06693cc0f71e72847f19 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 15 Mar 2020 21:53:46 +0530 Subject: split into lib and macros crates --- src/lib.rs | 70 ++++++++++++++++---------------------------------------------- 1 file 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 @@ -extern crate proc_macro; - use std::path::{Path, PathBuf}; -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, AttrStyle, Attribute, DeriveInput, Lit, Meta, MetaNameValue}; - -use serde::{de::DeserializeOwned, Serialize}; - -trait Config -where - T: Serialize + DeserializeOwned + Default, -{ - fn load() -> Result; - fn store() -> Result<(), String>; -} - -fn is_outer_attribute(a: &Attribute) -> bool { - match a.style { - AttrStyle::Outer => true, - _ => false, - } +pub use serde::{de::DeserializeOwned, Serialize}; +pub use directories::ProjectDirs; +pub use toml; +pub use serde_json; +pub use serde_yaml; + +#[derive(Debug)] +pub enum FondantError { + InvalidHomeDir, + ConfigParseError, + DirCreateErr(std::io::Error), + LoadError, + FileWriteError, + FileReadError, + FileOpenError, } -#[proc_macro_derive(Config, attributes(filename, filetype))] -pub fn config_attribute(item: TokenStream) -> TokenStream { - let mut ast: DeriveInput = syn::parse(item).unwrap(); - - let mut filename: Option = None; - let mut filetype: Option = None; - - for option in ast.attrs.into_iter() { - let option = option.parse_meta().unwrap(); - match option { - Meta::NameValue(MetaNameValue { - ref path, ref lit, .. - }) if path.is_ident("filename") => { - if let Lit::Str(f) = lit { - filename = Some(PathBuf::from(f.value())); - } - } - Meta::NameValue(MetaNameValue { - ref path, ref lit, .. - }) if path.is_ident("filetype") => { - if let Lit::Str(f) = lit { - filetype = Some(PathBuf::from(f.value())); - } - } - _ => {} - } - } - - println!("{:?} {:?}", filename, filetype); - - TokenStream::new() +pub trait Config: Serialize + DeserializeOwned + Default { + fn load() -> Result; + fn store(&self) -> Result<(), FondantError>; } -- cgit v1.2.3