4 ms·
I really want to know if the eventually arising full-blown web framework in rust still can claim "zero cost abstractions", and if this would translate into basi
by anonyfox 10y ago
I really want to know if the eventually arising full-blown web framework in rust still can claim "zero cost abstractions", and if this would translate into basically "the most performant/efficient way to write a web-app".
- leeoniya 10y agoprobably just to "serve" a web-app. until WebAssembly is a common thing.
- steveklabnik 10y agoSo, when what was to become tokio was first announced, we did a check to see how it compared to writing mio by hand. The two were within 0.3% (not a typo, one third of a percent) of each other. That was before any optimization work was done. One of the core premises of tokio is that this compiles down to the state machine you'd have to write by hand if you wanted to do asynchronous stuff. So yes, this is very much intended as a zero-cost abstraction.
- anonyfox 10y agoYes, I got that. So to build a "small" web framework like express.js, one could build a routing layer based on macros (like Phoenix/Elixir or rocket.rs do), plus JSON-serialization (Serde might do it) and a compile-time HTML-templating-engine, all of those leveraging zero-cost abstractions once Macros 1.1 land in stable, right? Then stuff like spinning up 1 OS-thread for every CPU core and scheduling requests in round-robin (?) style, and then wrap it all up into a developer-ergonomic thing. Since you probably have a way better insight into rust-dev and the ecosystem, can we stay tuned that this eventually will happen or are there still showstoppers somewhere?
- steveklabnik 10y agoYup! So for the next step up, see this example of using hyper with tokio: https://github.com/hyperium/hyper/blob/tokio/examples/server.rs https://github.com/hyperium/hyper/blob/tokio/examples/server... You could see how that match block functions as a router... I was literally playing around with this last night. There's a lot of experimentation going on in the server-side Rust web framework space right now, and I expect it to heat up even more now that tokio has had a release. > once Macros 1.1 land in stable, right? So to be clear, macros 1.1 gets you custom Derive, which is Serde/Diesel. It'll be stable in the next release in ~3 weeks. It won't get you the full ability to use any custom attribute, like https://rocket.rs/ https://rocket.rs/ uses. > Then stuff like spinning up 1 OS-thread for every CPU core This is not implemented in tokio yet, but in my understanding, it's coming.
- anonyfox 10y ago> a lot of experimentation going on in the server-side Rust web framework space This alone are awesome news! Having worked with literally dozens of web frameworks, I have a sincere interest to see what emerges from the rust space. I can't pinpoint or prove it, but many developers seem to care about doing stuff "the right way" instead of getting something out the door that works maybe Ok. I really wait for the "this is it"/"we couldn't possibly solve this better" moments that might arise from such experimentations. > macros 1.1 gets you custom Derive, which is Serde/Diesel ... basic building blocks for all things web I'd say. Looks like the next stable release will arrive just-in-time for things to emerge. And then there might be the next wave of rust-users/developers that want to built upon such rock-solid foundations, like me. Really, I'm excited like I haven't been in many years!
- jononor 10y agoReally minor thing, but I for instance like how in Hyper.rs types are used to enforce (at compile time) that one does not try to write headers after having started or sent the body of a response. http://hyper.rs/hyper/v0.10.0/hyper/server/index.html#an-aside-write-status http://hyper.rs/hyper/v0.10.0/hyper/server/index.html#an-asi... Good sign that we are starting to leverage the compiler to verify such invariants.
- leshow 10y agoWhat does rocket.rs use that makes it different from serde as far as custom derivations go?
- steveklabnik 10y agoCustom derive: #[derive(Serialize)] <- you can write anything inside the ()s Full on procedural macros, attribute style: #[get("/hello/<name>/<age>")] <- you can write anything inside the []s
- stepik777 10y agoCan rocket use `#[derive(get("/hello/<name>/<age>"))]` instead of `#[get("/hello/<name>/<age>")]`?