diff --git a/Cargo.toml b/Cargo.toml index a30a6d0..a9a2674 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ description = "Simple rust caching tools" keywords = ["caching"] license = "MIT" readme = "./README.md" -version ="2.4.0-beta" +version ="2.4.1-beta" edition = "2021" [workspace.package] @@ -18,8 +18,8 @@ readme = "./README.md" license = "MIT" [dependencies] -simple_cache_macros = "2.4.0-beta" -simple_cache_core = "1.0.0-beta" +simple_cache_macros = {path = "./macros"} +simple_cache_core = {path = "./core"} futures = "0.3.28" [workspace] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index e838f9b..874821d 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -7,7 +7,7 @@ keywords.workspace = true repository.workspace = true readme.workspace = true license.workspace = true -version = "2.4.0-beta" +version = "2.4.1-beta" [lib] proc-macro = true @@ -18,3 +18,4 @@ quote = "1.0.32" proc-macro2="1.0.66" syn = {version="2.0.28", features=["extra-traits", "full"]} futures = "0.3.28" +proc-macro-error = "1.0.4" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 74d49e7..606e027 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -2,6 +2,7 @@ use darling::ast::NestedMeta; use darling::{Error, FromMeta}; use proc_macro::TokenStream; use proc_macro2::Span; +use proc_macro_error::proc_macro_error; use quote::quote; use syn::punctuated::Punctuated; use syn::token::Comma; @@ -24,6 +25,7 @@ struct FunctionReturnType<'a> { /// This proc macro is designed to cache function calls with a /// time-to-live (TTL) duration. #[proc_macro_attribute] +#[proc_macro_error] pub fn ttl_cache(attr: TokenStream, item: TokenStream) -> TokenStream { // Parse the anotated function signature and extract various properties let function = parse_macro_input!(item as ItemFn); @@ -66,21 +68,16 @@ pub fn ttl_cache(attr: TokenStream, item: TokenStream) -> TokenStream { let only_ok = only_ok.is_some(); let only_some = only_some.is_some(); let function_return_type = ty; - if only_ok || only_some { - assert_ne!( - only_some, only_ok, - "`only_some` and `only_ok` cannot both be set" - ); + if only_ok && only_some { + proc_macro_error::abort_call_site!("`only_some` and `only_ok` cannot both be set"); } - if only_ok { - assert_eq!( - only_ok, is_result, + if only_ok && !is_result { + proc_macro_error::abort_call_site!( "`only_ok` can only be applied if the function's return type is a `Result`" ); } - if only_some { - assert_eq!( - only_some, is_option, + if only_some && !is_option { + proc_macro_error::abort_call_site!( "`only_some` can only be applied if the function's return type is an `Option`" ); }