Skip to content

Commit

Permalink
rename the origin to no_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
omid committed Aug 30, 2023
1 parent 39f47b4 commit 89747ba
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cached_proc_macro/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {
result
};

let origin_fn_ident = Ident::new(&format!("{}_origin", &fn_ident), fn_ident.span());
let no_cache_fn_ident = Ident::new(&format!("{}_no_cache", &fn_ident), fn_ident.span());

let lock;
let function_origin;
let function_no_cache;
let function_call;
let cache_type;
if asyncness.is_some() {
lock = quote! {
let mut cache = #cache_ident.lock().await;
};

function_origin = quote! {
async fn #origin_fn_ident(#inputs) #output #body
function_no_cache = quote! {
async fn #no_cache_fn_ident(#inputs) #output #body
};

function_call = quote! {
let result = #origin_fn_ident(#(#input_names),*).await;
let result = #no_cache_fn_ident(#(#input_names),*).await;
};

cache_type = quote! {
Expand All @@ -218,12 +218,12 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {
let mut cache = #cache_ident.lock().unwrap();
};

function_origin = quote! {
fn #origin_fn_ident(#inputs) #output #body
function_no_cache = quote! {
fn #no_cache_fn_ident(#inputs) #output #body
};

function_call = quote! {
let result = #origin_fn_ident(#(#input_names),*);
let result = #no_cache_fn_ident(#(#input_names),*);
};

cache_type = quote! {
Expand Down Expand Up @@ -271,7 +271,7 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {

// make cached static, cached function and prime cached function doc comments
let cache_ident_doc = format!("Cached static for the [`{}`] function.", fn_ident);
let origin_fn_indent_doc = format!("Origin of the cached function [`{}`].", fn_ident);
let no_cache_fn_indent_doc = format!("Origin of the cached function [`{}`].", fn_ident);
let prime_fn_indent_doc = format!("Primes the cached function [`{}`].", fn_ident);
let cache_fn_doc_extra = format!(
"This is a cached function that uses the [`{}`] cached static.",
Expand All @@ -284,9 +284,9 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {
// Cached static
#[doc = #cache_ident_doc]
#cache_type
// Origin function
#[doc = #origin_fn_indent_doc]
#visibility #function_origin
// No cache function (origin of the cached function)
#[doc = #no_cache_fn_indent_doc]
#visibility #function_no_cache
// Cached function
#(#attributes)*
#visibility #signature_no_muts {
Expand Down

0 comments on commit 89747ba

Please sign in to comment.