Introducing Laravel Rust
9 points by ajeetdsouza
9 points by ajeetdsouza
I've been professionally writing Laravel for 6 years.
At some point in that period I think that the framework was completed. Volt and Folio were the first round of features that seemed to be searching for a problem. This is a whole 'nother level of searching for a problem.
Is it? I have no dog in the fight (Django person here), but huge performance improvements with stronger types and (theoretically) memory guarantees are pretty compelling. If you’re committed to continuing to write things by hand then yes, this is pointless. But if someone said “here are all the idioms from Django except in a different language that has some real advantages”, I’m all ears.
Agreed.
I use Rust everywhere it's practical for the strong compile-time guarantees which make it easier for me to work on a project I haven't touched in a while without feeling I'm going to burn myself out either writing or manually imitating a high-coverage test suite to achieve confidence that I haven't subtly broken something.
I still use Python with mypy --strict (and beyond) for SQL-y things and anything I'd use Django for because, so far, Rust has lacked an ORM with South/Alembic-style migrations, abstraction over "For this install, we want something other than SQLite", abstraction over SQLite's limited ALTER TABLE, and Django's ecosystem of reusable apps with cross-cutting integration. (And all without the assumption that the end-user will have JavaScript enabled. "Do unto others..." and I consider it a deal breaker whenever I land on a vendor's website and they're not even competent enough to produce a website that can render and navigate properly without being whitelisted in my uMatrix.)
3 pages of procedural macros—55 files as of posting—in just the main framework (to say nothing of intertia-laravel-rust) is a lot to consume, maintain, and extend. My understanding is and experience has been that proc-macros are one of the sharper-edged tools in the Rust toolbox, and should usually only be reached for as the last'est of last resorts.
Problems for which I've reached for macros too soon have tended to end up being better solved by rethinking whatever my implementation was to more gracefully "swim with the current" of Rust's design of structs and traits. And like most composition-over-inheritance-style problems (which tend to rear their heads when ones tries to do OOP-flavor stuff in Rust), the optimal solution is usually the inversion of the current implementation: eg. reverse the structure of the data/logic, facts/intents, etc.
The first lines of code shown are these:
// src/routes/web.rs
use laravel::prelude::*;
use crate::http::handlers::posts;
use crate::models::User;
pub fn routes(route: &mut Router) {
route.get("/greeting", async || "Hello World");
route.get("/users/{user}", async |user: User| user.name);
route.get("/posts", posts::index);
route.get("/posts/{post}", posts::show);
route.post("/posts", posts::store);
}
I wouldn't call this good Rust code. Router is included in the prelude for everything despite only being relevant fot router stuff. The other imports are a bit convoluted too. You end up having an http, models and routes module all importing from each other. It would he cleaner to have a posts module with submodules for handlers (including the router) and models.
Looking into the repo, it seems be completely slop. Why should I use this over a battle tested crate like axum?