
Sapper, a lightweight web framework written in Rust - dumindunuwan
https://github.com/sappworks/sapper
======
killercup
It's good to see new web-focused projects in Rust, I think it can be a really
great language for this kind of thing. But to be honest, I'm looking forward
to seeing what will be considered the go-to approach for Rust web applications
_in a year_ or so.

There is much experimentation going on right now, with cool little innovations
here and there, but I have yet to see an approach that looks really new and
Rust-y to me.

For example: Rust's type system certainly has some nice properties to track
dependencies between middlewares[^1] but I'm not convinced middlewares are
even the best approach possible here. Also, it will be interesting how a
framework based on async IO will look and what tricks/syntactic sugar/macros
will be employed to keep boilerplate code down.

This is a pretty big order, of course: While I enjoy using small libraries, a
well designed web framework requires a lot of organisational effort for all
the small pieces to fit together nicely. I think most of the 'small pieces'
are already there or at least well under way, by the way. For example: The
async (mio) branch of hyper looks pretty solid for HTTP1/2, the Diesel ORM is
fantastic (and will, according to creator Sean Griffin, soon hit 1.0), and
handling JSON will only get better with future versions of serde.

[^1]: As recently discussed in
[https://chrismorgan.info/blog/tween.html](https://chrismorgan.info/blog/tween.html)
and some other posts concerning the use of sessions types in Rust.

~~~
bjz_
> For example: Rust's type system certainly has some nice properties to track
> dependencies between middlewares[^1] but I'm not convinced middlewares are
> even the best approach possible here.

There's a good discussion of this on /r/rust:
[https://www.reddit.com/r/rust/comments/4lz92j/tween_a_middle...](https://www.reddit.com/r/rust/comments/4lz92j/tween_a_middleware_library_experiment/)

I'm pretty interested in tomakas's approach, which seems to avoid the approach
of middlewares, in favor of explicitness:
[https://www.reddit.com/r/rust/comments/4lz92j/tween_a_middle...](https://www.reddit.com/r/rust/comments/4lz92j/tween_a_middleware_library_experiment/d3rhglt)

------
steveklabnik
Fun fact: crates.io is written with a Rust + Ember + Postgres stack, though
with its own framework, condiut, rather than Sapper. It uses about 30
megabytes of memory resident. Coming from Rails world, this was... quite the
change.

Also fun fact: we had a small amount of downtime today :( Type safety can't
protect you from everything. [https://users.rust-lang.org/t/crates-io-is-down-
fixed/6060/6...](https://users.rust-lang.org/t/crates-io-is-down-
fixed/6060/6?u=steveklabnik)

------
Thaxll
The more I look at Rust the less I like the syntax, what are those? "Ok(())"

~~~
lossolo
Or this:

pub fn from_bytes(bytes: &'a [u8]) -> IResult<&'a [u8], C<'a>> { ... }

or something like this:

fn parse_response<'a>(bytes: &'a [u8]) -> IResult<&'a [u8], C<'a>> {
switch!(bytes, tuple!(be_u32, be_u32), (::CONNECT_ACTION_ID, tid) =>
map!(be_u64, |cid| B::new(tid, ResponseType::Connect(cid)) ) |
(::ANNOUNCE_IPV4_ACTION_ID, tid) => map!(call!(W::from_bytes_v4), |ann_res| {
C::new(tid, ResponseType::Announce(ann_res)) }) |

~~~
steveklabnik
You're missing a <'a> in the declaration there ;)

"from_bytes is a public function with one lifetime parameter, a. It takes one
argument, a slice of u8 with the lifetime 'a, and returns an IResult, which
gives back a slice of u8 with the lifetime 'a in the success case, and some
type C, which is also parameterized with the lifetime 'a, in the failure
case."

This is not really normal rust code; it's nom, which is a very macro-heavy
DSL. There are decent upsides, and I love nom, but its downside is that it
does look a bit odd.

~~~
Sammi
It doesn't look a bit odd. It looks impenetrable.

~~~
steveklabnik
Well, without all the whitespace, it is ;)

~~~
andrewflnr
Seriously, you can't strip out the whitespace and then pretend to make
reasonable critiques of readability.

------
Corianderine
Interesting, when would I use this (and Rust) over some other new web
frameworks like Amethyst (Crystal) and Jester (Nim)?

[https://github.com/Codcore/amethyst](https://github.com/Codcore/amethyst)

[https://github.com/dom96/jester](https://github.com/dom96/jester)

------
mikerichards
Can someone recommend a good IDE or editor with good IDE-like features for
Rust? I think it's time for me to take the plunge and start learning a little
bit about Rust.

Also, I'm assuming the windows support is good these days?

~~~
dikaiosune
I'm using Atom (on a fairly speedy machine, VS Code has some solid plugin
support too) with:

    
    
        * atom-beautify (with rustfmt installed, `cargo install rustfmt`)
        * language-rust
        * linter + linter-rust (using cargo check, `cargo install cargo-check`)
        * you-complete-me (but YCM is not fun to install, so I'd recommend the racer plugin, both require the Rust source cloned and installed somewhere)
    

Altogether, those plugins give a pretty good Rust experience.

~~~
TylerE
Is this like anywhere even close to the functionality of something like
IntelliJ? Doesn't really sound like it. Linting and formatting, and completion
does not an IDE make. How much code intelligence and introspection is there?

~~~
dikaiosune
Not nearly as much as intellij. However the "linting" in this case is really
just highlighting for compiler warnings and errors which are _quite_ good in
Rust. That said, you can use clippy ([https://github.com/Manishearth/rust-
clippy](https://github.com/Manishearth/rust-clippy)) to get some pretty solid
static code analysis as a compiler plug in.

Also, I am very closely following the progress of the rust intellij project,
it's coming along nicely.

------
yarper
This framework seems to have practically the same API as nickel.rs
[https://github.com/nickel-org/nickel.rs](https://github.com/nickel-
org/nickel.rs)

