fengsp / pencil

A web application microframework for Rust
https://fengsp.github.io/pencil/
Other
872 stars 43 forks source link

Allow passing closures to routes. #14

Open eltair opened 8 years ago

eltair commented 8 years ago

While trying pencil, I almost immediately wanted to pass closures to the route functions instead of function pointers. In particular, this allows for capturing config information loaded at startup (eg api keys).

There are more places that take function pointers which should probably also be changed before this is merged, but I wanted to get your feedback first.

fengsp commented 8 years ago

@eltair I'd appreciate it if you can add some working example code in the comment. Let's see how the api looks like.

eltair commented 8 years ago

Your existing hello example app should continue to work without modification, but I added a few more routes that show the use of closures.

scorphus commented 8 years ago

👍

afaur commented 8 years ago

I wanted to get this work into my fork of master to test with.

I did a rebase and got it to merge into my fork of master, and then located an issue that I overlooked when deciding what to keep or not. I also found an issue with the example that I corrected.

If you want to see what worked for me to get this into a recent master it can be found here: https://github.com/afaur/pencil/tree/closures

I also have a simple example pencil web app that was forked and adjusted from archaelus. I modified it to set up a closure route for testing.

I also added a few instructions to the readme to explain how to set it up to test the closures branch of pencil. It can be found here: https://github.com/afaur/rello/tree/closures-branch-test