Is Rust Ready for the Web Yet? (2020)
blog.devgenius.io
blog.devgenius.io
I will continue using Rust for embedded, 3D graphics, and desktop PC programs, but won't touch it for websites until this is solved.
Auto generated admin stuff is pretty rare in anything outside Django I think, though I don't see why one couldn't make those for Rust. I suppose most devs would probably want their CRUD APIs to function on their own and use those for management if performance is critical enough that you'd prefer Rust over something like dotnet or Java.
Just wanted to say that anywhere from Ruby on Rails, to Laravel, to Yii, to... Pretty much every major web framework in the most common language used for web dev (php, python, ruby) has a builtin admin (among tons of other stuff).
Edit:
> Diesel
Diesel doesn't come close to where the ORMs of Django or RoR stand. Not by chance. Having to write by hand SQL (according to Diesel's docs) is something that modern web frameworks solved years ago. And I'm not even talking about automatic mapping of models to tables, automatic migrations, etc... Diesel is simply not anywhere near what a web dev would expect. Not saying that Diesel is bad, just that it's not in the same category where current ORMs stand.
And in my experience going from Django to anything in Rust will be at least 10 times the boilerplate and some things will be very very annoying to handle, especially things like sharing parts of model, automating things like creation / update metadata for all models, and even sharing authentication mechanism for most routes can be annoying depending on the way you have to do authentication (in my case Firebase auth so authenticating sometimes does require making async calls... And that's a trouble).
The API layer options I have seen are more like Flask rather than generating full APIs from the model schema.
I’d love for this to be the case but Rust is not close to having a Django yet. Part of the problem is that structs are very inflexible; there is no equivalent of the metaclass manipulation that Django does.
You could perhaps build something equivalent with macros? But there is lots of syntactic sugar in Python like descriptors that let you generate really clean class-level APIs.
Both sqlx and diesel have DB migrations. We use them. Sqlx is actually type checked too, which is awesome.
There are plenty of 3rd party auth and email packages (though we didn't use any, so I can't attest to them). It was quick enough to grow our own internal stuff, which we now reuse internally.
Rust is fantastic for working with audio or video on the server. We're starting work on rendering 3D workloads headlessly.
Another thing Rust can do that Python can't dream of - our servers have easy to manage background threads! We can launch async processes or have long-running background processes (infinite loops with periodic sleeps) that update singletons (Arc<Lock<T>>) of important caches, which is way faster and more durable than Redis in certain cases. Actix makes these a breeze to work with.
I'm building an app powered by Rust, and I love it, but I'd rather use Elixir for the Web facing part.
Perhaps when the whole async thing is more ergonomic I'll reconsider, but there is no chance any Rust framework can be as nice as any language running on the BEAM (or PHP, or Python, or Ruby, or Go, or Lisp), especially not as nice as Elixir can be as a website backend.
Use the right tool for the job.
Not sure what it might take for someone to write database connectors for it but it does look promising.
What's wrong with
router.get("/foo", |req, res| -> Response {
...
});I can see maybe using Rust for some performance critical parts but for the daily CRUD or API? I don't get how you could justify using it. (In a professional context that is, if it's just for fun, go ahead, of course.)
There are so many amazing backend-languages with huge ecosystems be it Elixir, PHP, Golang, Node or whatever you favorite poison may be. You would miss out on so much productivity.
Rust is amazing but it solves a very specific problem while most of the software world is better off using garbage collected languages.
It's no coincidence that web is full of bloated frameworks - because the emphasis is on cranking out yet another generic page not optimising things to within an inch of its life.
Javascript is the only real competition, but the needed shims are lossy at times.
C++ is the closest, but Dioxus and Cacao are nicer than anything in the C++ ecosystem AFAICT.
It's perhaps not the ideal language for any of those, but there's substantial benefit to having your whole team in the same ecosystem.
This isn't a dig on Rust, but wherever Rust runs, so does C++. There are a lot of dimensions where Rust is better, but definitely not "runs everywhere" and "ecosystem".
My suspicion is that this is because QT widgets sort of look like native widgets but aren’t quite there, causing it to fall into some kind of “uncanny valley” analogue.
You can use the win32 API on Windows and Gtk on GNOME, but for KDE and all else you'll need to use some kind of Qt wrapper that has the problems you encounter.
with this demo: https://github.com/DioxusLabs/example-projects/tree/master/e...
QT is unusably slow. Dioxus is indistinguishable from a Javascript app.
Yes, QT on the desktop is very good. There are bindings for Rust too, as there are for most languages, but the most integrated one is C++. (I'd say the close integration is just not worth it.)
Anyway, I don't know why people want so badly a single language to run on every context. They are forfeiting a lot of value for that.
#[get("/")]
#[actix_web::main]
std::io::Result<()>
HttpResponse::Ok().body("Hello world!")
I mean, blegh! Anyway, just making conversation please don't take offense, some people think Ruby looks like ass.There's (at least) three things going on in the snippet you posted. One is that actix, like most (all?) Rust frameworks, is macro based; that code would look pretty similar if it were written in Flask, but with different syntax.
Another is that the strict type system can lead to some heavy verbosity, eg having to populate the generic in `std::io::Result<()>` with unit (`()`) just to say you're not returning anything.
Regarding `HttpResponse::Ok().body("Hello world!")`, the builder pattern is also pretty verbose and some people don't like it, but it's friendly to the type system and you can use it to provide really cool guarantees (like not being able to call `build()` until you've fully populated the builder).
Generally I'm of the mind that computers should conform to the needs of people and not the other way around, but programming language are a place where I'm willing to make many concessions, since as a rule humans are smarter than compilers.
But I think sometimes, people use "syntax" in a blanket "how the language looks" way — that is, whether it's symbol-heavy, whether it's word-based, whether it's information-light or information-dense, and so on. This makes it more a function of which features of expressivity the language chooses to expose, than the individual syntactic choices that determine which characters we use and for what. Again in Rust's case, it has attributes, it has namespace separators, it has the zero-tuple, it has generics, and it has lifetimes, all of which need some way to be expressed.
Don't get me wrong, you're allowed to not use a language if you don't like the way it looks visually. Or maybe it makes good use of a certain character that's hard to type on your particular keyboard layout. That's fine. I also can't decree that either of these uses of the term "syntax" are wrong. But when we're talking about language syntax, it's important to remember when you're talking about syntax, and when you're instead talking about language features. If you don't like the way lifetimes look, that's one thing; if you don't like the way lifetimes make you change the way you write code, that's another.
So I have to ask: of those four code snippets, how would you prefer to write them? What would you change? And can you get away with making those changes without breaking anything else?
Salvo is also great: https://salvo.rs
If I interviewed somewhere that used Rust for web apis, I'd be very hesitant because this isn't really what Rust is good at (yet?), and someone chose it because they wanted to try it more than use the right tool for the job.
* it's relatively easy to write code that will pretty much never crash. yes, Rust will not prevent all of the bugs, but it will prevent almost all of the things that end up as a runtime exception in dynamic languages. So ou will not end up with an error tracker full of errors
* refactoring is so much easier in Rust - I can enter a new project, change a bunch of stuff and after I fix compile errors and tests my confidence that I didn't break anything is like 10 times higher than in Ruby or Python
* while most of the time speed is not a major concern for backend development, it sometimes is a huge bonus. There were cases in the past when I had to spend a lot of time to optimise Ruby code, because it was just too slow (imagine rendering a lot of HTML, doing computation that is hard to do on the DB side etc)
* handling JSON with serde is just on another level
* Rust is very versatile. When a company starts using a language, they will naturally try to fit as much stuff into the language as possible, after all if you have mostly Python devs, you will prefer Python. A lot of people say "just use the right tool for the job", but even if there was something like "the right tool for the job", in practice it's more like: if the downsides of using our primary tech are huge, let's consider introducing a new language, otherwise let's stick with what we have. I've seen it numerous times in the past. I feel like with Rust the downsides of using it for most of the stuff are much smaller than for example for most of the other languages
There is some argument that you (or at least some developers) can be more productive with a strongly-typed ORM, but I think FastAPI / Django-ninja capture most of these benefits in the Python ecosystem so it’s not a big win in this dimension IMO.
But in summary it’s a perf vs productivity trade-off.
I was delighted just a few weeks ago to go from nothing to a rest server, redis connection, database connection and templating out dynamic html with rust after a few hours of tinkering.
https://scribe.rip/is-rust-ready-for-the-web-yet-9ec38c01dca...