iliana / rust-crowbar

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)
https://docs.rs/crowbar
Apache License 2.0
197 stars 16 forks source link

introducing #[lambdafn] #53

Closed softprops closed 5 years ago

softprops commented 5 years ago

now that proc-macro works on stable I wanted to introduce a new way to export lambda functions with crowbar, attributing bare functions. This is something I'm also experimenting with the lando crate. Included in this pull is a doc example but in a nut shell the idea is simple. Any function with the attribute #[lambdafn] will get its declaration parsed expecting two args ( assuming event and context ) and a return value. its function name will get used to synthesize.

lambda!("functionname" => functionhandle);

I think this is going to be a direction more crates are taking so I wanted to give this an early try in crowbar.

Initial thoughts I had were me wanting to reuse lambda for the proc-macro name #[lambda] but that conflicts with the declarative form. lambdafn was kind of comprise but I'm open to suggestions.

Let me know what you think @ilianaw.

softprops commented 5 years ago

One notable drawback to this that I just realized while testing is that this limits a crate to one function as each func makes a call out to the initializer macro. This may be fine for many projects but it's notably limiting. Going to see if there's a way to limit this restriction

iliana commented 5 years ago

If we still have the old macro I’m not worried about that restriction for 0.3.0 as long as we document it and open an issue for resolving it.

softprops commented 5 years ago

Cool cool. Did have any thoughts/opinions on the attribute name? Rust can have attribute names that clash with macro names in the new unified path model otherwise I would have opted for just #[lambda]. Lambdafn is concise enough I think but I'm open to suggestions.

iliana commented 5 years ago

#[lambdafn] is a good name given that restriction.