Introducing Laravel Rust
Today, the initial beta version of Laravel Rust was released, merging Laravel's full-stack capabilities with Rust's unique features. This includes routing, middleware, sessions, authentication, database models, queues, mail, workflows, and testing aids. Laravel Rust isn't a simple translation of Laravel into Rust; it's a reimagining of Laravel in idiomatic Rust, tailored for a modern, high-performance stack, emphasizing developer experience in AI-driven applications.
Every new application comes with pre-installed agent skills to guide coding agents on crafting and testing Laravel Rust code.
Laravel Rust anticipates a future where humans will increasingly not write or manually read application code at scale. Hence, strong guardrails, strict compilers, and pre-loaded conventions are prioritized. It carries Laravel's battle-tested philosophies, conventions, and productivity into Rust, creating a high-performance full-stack framework designed to excel in the AI era, offering a robust foundation for developing ambitious, critical web applications.
At launch, Laravel Rust matches Laravel PHP on features, with any remaining discrepancies set to be resolved soon. The following sections detail some key features. Detailed documentation is available for comprehensive exploration, including authentication, encryption, file storage, task scheduling, console commands, and package development.
In benchmark tests using Laravel Cloud, Laravel Rust outperforms Laravel PHP by 18 times, consuming significantly less CPU and memory. This efficiency leads to reduced infrastructure costs, improved tail latency, and higher traffic capacity on a single server during traffic spikes.
Laravel Rust is constructed using Axum and Tokio, ensuring asynchronous processing throughout the stack: HTTP handlers, middleware, database queries, HTTP client, Redis, queues, S3, SQS, and WebSockets are all non-blocking. Blocking tasks like bcrypt password hashing and local disk I/O are offloaded to Tokio's blocking thread pool.
When a request waits for a slow database query, third-party webhook, or lengthy AI API call, these threads continue serving thousands of other requests, background tasks, and queue jobs without stalling.
Rust's type system enhances the framework significantly. Database column names, relationships, validated form inputs, authorization checks, and secret values are verified at compile time before deployment. At request time, Laravel maps the incoming request to registered routes defined in src/routes/web.rs and src/routes/api.rs. Handlers can be simple inline closures or complex modules under src/http/handlers.
For example, a request to /users/42 will fetch user 42 and pass it to the route, or return a 404 if no corresponding user exists. URLs to routes can be generated using macros like route!(posts::show, &post) and redirect!(posts::show, &post), ensuring URL generation is compile-time checked and thus immutable.
Laravel Rust supports defining incoming form and JSON payloads as Rust structs annotated with #[laravel::input] and field-level #[validate(...)] rules, creating fill structs from these definitions. Rigorous type checks ensure that column names, operators, and value types are validated, maintaining exact SQL syntax for conditions using &, |, and ! operators, bypassing nesting in where closures.
Database relationships are explicitly defined in Rust structs annotated with #[model] and field-level attributes such as #[belongs_to] and #[has_many]. Models are designed to load all necessary data upfront with the with keyword, preventing N+1 queries by design. Database migrations are also Rust files in database/migrations/ that compile into the application binary, allowing server-side migration without shipping source files.
Migrations run in transactions for PostgreSQL, SQLite, and automatically generate SQL for these databases. For complex queries or database-specific features, the db::query! macro enables direct SQL execution, capturing Rust variables, fields, and collections within braces, ensuring no string concatenation and preventing SQL injection by design.
Rewritten by urgent.news; may contain errors — check the original.
Source: laravel.com