jaemk / cached

Rust cache structures and easy function memoization
MIT License
1.58k stars 95 forks source link

Proc macro based version #13

Closed harryfei closed 4 years ago

harryfei commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Yes, it does.

https://github.com/rust-lang/rust/issues/38356#issuecomment-414548990

harryfei commented 6 years ago

Rust 1.30 (including proc macro) is released now.

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

csos95 commented 4 years ago

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)

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 commented 4 years ago

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.