Anyone know of any benchmarks? This seems to be built on top of hyper. I remember checking out hyper a couple months ago and being disappointed with its performance. Last I checked it was using synchronous IO, and was performing about an order of magnitude worse than equivalent Go. That could certainly change, but I'm hesitant to use Rust for an HTTP server like I would with Go until I see better performance.
Pencil: A Microframework Inspired by Flask for Rust
51–58 of 58 posts
Re: Pencil: A Microframework Inspired by Flask for Rust
#52 app.get("/", "hello", hello);
app.get("/user/", "user", user);
....
This reminds me of Pyramid more than Flask though, just my personal observation. The code looks pretty readable even from a non-Rust programmer.Re: Pencil: A Microframework Inspired by Flask for Rust
#53Earlier quoted context omitted.
I know very little Rust, but I was actually looking at how this could be done in Rust some time ago, but I didn't get anything working. All the routes (e.g. /foobar and accompanying function) needs to be collected by the "router" somehow which begs for a global route-container that the route macro (like Flasks route decorator) would need to add routes to, similar to how it is done is Flask, and, well, yeah, I couldn'…
There are a few different ways one could achieve this. The first options would be to generate a struct: struct RouteUser { route: &'static str, f: fn(_: &mut Request) -> PencilResult } Then given #[route("/user")] fn user(_: &mut Request) -> PencilResult {} You would hijack the `user` function to return an instance of the struct. fn user() -> RouteUser { // The actual function the user wrote: fn user(_: &mut Request)…
Re: Pencil: A Microframework Inspired by Flask for Rust
#54Great start. Instead of numeric codes, perhaps use an enum for all the acceptable status codes? As Jane Street Says, make illegal state unrepresentable.
This is a good slogan, but there's some subtleties when it comes to HTTP status codes. That is, there are the defined ones, but any number is legit, so you end up with an enum with a member that's basically "anything we don't know about", so it's not as clear-cut as it is in other situations.
data StatusCoode
= Ok200
| Missing404
| Error500
| OtherStatusCode Int
To rephrase the slogan a bit - make an illegal state a bit more difficult to represent or at least the risk of an illegal state clear to the programmer.Re: Pencil: A Microframework Inspired by Flask for Rust
#55Earlier quoted context omitted.
This is a good slogan, but there's some subtleties when it comes to HTTP status codes. That is, there are the defined ones, but any number is legit, so you end up with an enum with a member that's basically "anything we don't know about", so it's not as clear-cut as it is in other situations.
Good point, this is where Rust's flexible enums are an advantage relative to C-style. If you'll forgive the Haskell syntax, you can have something like: data StatusCoode = Ok200 | Missing404 | Error500 | OtherStatusCode Int To rephrase the slogan a bit - make an illegal state a bit more difficult to represent or at least the risk of an illegal state clear to the programmer.
Re: Pencil: A Microframework Inspired by Flask for Rust
#56Earlier quoted context omitted.
Good point, this is where Rust's flexible enums are an advantage relative to C-style. If you'll forgive the Haskell syntax, you can have something like: data StatusCoode = Ok200 | Missing404 | Error500 | OtherStatusCode Int To rephrase the slogan a bit - make an illegal state a bit more difficult to represent or at least the risk of an illegal state clear to the programmer.
Exactly: https://github.com/hyperium/hyper/blob/master/src/status.rs#...
Re: Pencil: A Microframework Inspired by Flask for Rust
#57Earlier quoted context omitted.
Exactly: https://github.com/hyperium/hyper/blob/master/src/status.rs#...
My bad.. I was just basing my comment off the readme. In general, I love what you guys are doing and my team is looking closely at Rust and Leaf.
Re: Pencil: A Microframework Inspired by Flask for Rust
#58The magic of Flask is that that thing is full of state and globals you just import and they work, like request, app, session.