6 ms·
> Rust developers generally like these properties, predictability and explicitness, instead of magic. That’s why I’m quite surprised that most Rust web framewor
by kibwen 4y ago
> Rust developers generally like these properties, predictability and explicitness, instead of magic. That’s why I’m quite surprised that most Rust web frameworks went another route.
Ecosystems are rarely monoliths, and I assume that the people writing web frameworks in Rust are likely to have experience with (or at least be inspired by) more magical frameworks in other (usually more dynamic) languages, whereas the libraries that eschew magic are presumably written by people with prior experience in low-level languages. The fact that Rust has some amount of appeal to both of these crowds (not to mention the functional programming folks) makes it a bit of a melting pot.
- pjmlp 4y agoAs if macros weren't their own kind of magic.
- bryanlarsen 4y ago`cargo install cargo-expand` to demagickify.
- pjmlp 4y agoI bet many won't understand the runes of serde, when there is a whole conference talk explaining how it works.
- fire 4y agoI wonder if macros are a type of magic that can be reasoned about more sanely than other types of magic?
- dathinab 4y agoThe handlers are less hard to reason about then a lot of macros. You don't have to understand the type magic which makes them work. At least if you look at the more relevant frameworks (actix-web, axume) they basically boil down to calling a fn foo(x: A, y: B) -> Result<Body, Error> as roughly let x = A::from_request(&req, &mut payload).await?; let y = B::from_request(&req, &mut payload).await?; foo(x, y)?; and _nothing_ more. There is no special handle first/last parameter different logic or anything. They way they handle not copying the payload (request body) is by moving it (a reference to it) out of the request (or here payload). The reason the performance for micro-benchmarking extractors is different depending on the order has less to do with the general design and more the typical "I reordered parameters and now optimizations trigger differently" problem. (Probably some in-lining and const propagation allowing eliminating some checks but just on one order, anyway not specific to web frameworks at all and can also happen with their approach, but probably less likely if I should guess).
- twic 4y agoNo, indeed, the opposite. In Rust, these will surely be procedural macros, which comprise functions written in Rust which operate on Rust code, represented as token streams. The compiler compiles the macro, lexes your code, feeds it to the macro, gets a token stream back, parses that, and that's what it compiles. Understanding a magic handler function involves understanding a particular subset of features of the Rust type system, and operating that mechanism in your head to see what happens. Understanding a proc macro involves understanding arbitrary Rust.
- fire 4y ago...oh dear