nickel-org / nickel.rs

An expressjs inspired web framework for Rust

Home Page:http://nickel-org.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simple example without macros

flosse opened this issue · comments

Could you add two simple examples with handler functions instead of middleware!{} and router!{}? Like server.get("foo/bar", my_foo_bar_handler)?

@Ryman do we ever get to write this?

    s.get("**", |_req, res| {
        res.send("hello world");
      });

I know that we talked about that long time ago and there was some issue in Rust that was preventing us from writing this. Do you know what's the state of this?

These still fail, so at least the simple replacement doesn't work: https://github.com/nickel-org/nickel.rs/tree/master/tests/compile-fail

I had a similar problem in something else recently and managed to bring the lifetime into the trait itself and that got things working, I haven't tried with nickel but it might work out, although the semantics of the lifetimes are probably changed 😟 I'll maybe follow up with someone on irc.

Another option which I've considered since we added mount, is to make most of the get, put, blah methods take closures explicitly, and leave add_route to handle Middleware (on the basis that a lot of middleware being added via these methods is probably more correct to be handled via mount now).

If we can make get, put, blah take closures explicitly and wrap them into Middleware down the road, wouldn't it then be possible to implement Into<Middleware> for such closures and just make get, put, blah take those? I'm probably oversimplifying things ;)

Wouldn't it be possible to implement Into for such closures and just make get, put, blah take those? I'm probably oversimplifying things ;)

I think it would need to be Into<Box<Middleware>> which requires boxing always (which may not be so bad since we box further down the chain most of the time), or <M:Middleware, T: Into<M>> (but that would need type annotations I think? I do think that since inference is already failing, I'm unsure if adding an extra layer of type-indirection would really help it in any way, but I'd love to see it work!