Live data from Hacker News

Pencil: A Microframework Inspired by Flask for Rust

fengsp.github.io

1–10 of 58 posts

Re: Pencil: A Microframework Inspired by Flask for Rust

#5
I've found that whenever I start a small web project in a new language, I always look for the "Flask" of that language. I love using a framework that gives the bare essentials and nothing else.

I don't use Rust, but your code examples look great! I understand that Rust has less opportunity for "magic" to clean things up (for example, in Python you can use a decorator to specify a route for a function), but otherwise it looks very clear. Awesome work!

Re: Pencil: A Microframework Inspired by Flask for Rust

#6
post #3

Looks good! I don't know how I feel about using OK for anything but 200 responses though.

Well, 100- and 300- class respones aren't errors, but yeah, 400- and 500- might make more sense as Err.

You could also look at it from another point-of-view. Ok() means that I am able to fully handle this request, even if it's an HTTP error code, and Err being "nope, don't know. Sorry bud".

Re: Pencil: A Microframework Inspired by Flask for Rust

#7
post #5

I've found that whenever I start a small web project in a new language, I always look for the "Flask" of that language. I love using a framework that gives the bare essentials and nothing else. I don't use Rust, but your code examples look great! I understand that Rust has less opportunity for "magic" to clean things up (for example, in Python you can use a decorator to specify a route for a function), but otherwise…

There's probably some opportunity to use custom annotations in Rust to achieve the same thing.

    #[route("/foobar")]
    fn user(_: &mut Request) -> PencilResult {
        // ...
    }
However, procedural macros are unstable, but Rust is able to do amazing things with macros.

Re: Pencil: A Microframework Inspired by Flask for Rust

#9
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.

Re: Pencil: A Microframework Inspired by Flask for Rust

#10
post #5

I've found that whenever I start a small web project in a new language, I always look for the "Flask" of that language. I love using a framework that gives the bare essentials and nothing else. I don't use Rust, but your code examples look great! I understand that Rust has less opportunity for "magic" to clean things up (for example, in Python you can use a decorator to specify a route for a function), but otherwise…

I'm a huge fan of flask but I actually prefer the approach of not using decorators. Without decorators its easy to see all the paths in one area and they get type-checked in rust.
Post reply on HN