Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proc macro based version #13

Closed
harryfei opened this issue Sep 30, 2018 · 5 comments · Fixed by #33
Closed

Proc macro based version #13

harryfei opened this issue Sep 30, 2018 · 5 comments · Fixed by #33

Comments

@harryfei
Copy link

harryfei commented Sep 30, 2018

Do you have a plan to rebuild the macros based on the proc_macro?

Those are sweeter.

#[cached(Fib)]
fn fib(n: u64) -> u64 {
     if n == 0 || n == 1 { 
        return n; 
      }
      fib(n-1) + fib(n-2)
}
@jaemk
Copy link
Owner

jaemk commented Sep 30, 2018

I would love to. I haven't been following proc_macros though, are they going to be stable soon? I probably won't do anything until they're in stable

@harryfei
Copy link
Author

harryfei commented Oct 1, 2018

Yes, it does.

rust-lang/rust#38356 (comment)

@harryfei
Copy link
Author

Rust 1.30 (including proc macro) is released now.

https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html

@csos95
Copy link
Contributor

csos95 commented May 29, 2020

I was having some issues with rust complaining that it couldn't figure out what type to use for return values with the regular macro so I decided to give this a shot.

Here's the list of attributes that I'm working on (all of these are optional)

  • name = String - cache name (default is uppercase of function name)
  • unbound - use unbound cache (default cache type)
  • size = usize - use sized cache
  • time = u64 - use timed cache
  • key = "Type" - the type to be used for the cache (required when convert is set)
  • convert = "Block" - use a block to convert inputs into the key (required when key is set)
  • result - only cache the result if it is Ok
  • option - only cache the result if it is Some

I'm using darling for the attributes parsing and it doesn't implement parsing Type or Block so right now the key type and convert block both have to be put in a string and parsed separately.

I should have the unwrap attribute implemented on Friday or Saturday.
Once I have that done I'll fork, add the proc macro as a sub crate, and make a pull request.

Edit: I realized that having one attribute for both result and option wouldn't work since it would have to be based on parsing out the return type name and the user could have aliased the result/option type or be using their own. I changed it to be separate result/option attributes.

@csos95
Copy link
Contributor

csos95 commented May 29, 2020

I finished with this set of attributes, now I'm going fork and add as a subcrate.
I'm using the visibility of the input function for the output function and cache so this should also fix #15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants