Skip to main content

Crate larust_macros

Crate larust_macros 

Source
Expand description

Procedural macros for Larust. #[controller] lands once it has real payload (M6) - see rust-laravel.md’s milestone plan for why it wasn’t built speculatively.

Macros§

error_view
error_view!("404"): compiles resources/views/errors/404.blade.xr if the app defines one, else Larust’s own built-in default page for that status - always produces a String. See error_view.rs’s own doc comment for the override mechanism’s limitations (no context bindings, so no @wire/@can/@role/persist globals, and best kept self-contained rather than @extends-ing a session-aware layout).
view
view!("posts.index", { posts }): reads, parses, and resolves resources/views/posts/index.blade.xr (including any @extends layout chain) at compile time, and generates code that renders it into a View. Interpolated expressions ({{ user.name }}) and directive conditions/iterables (@if(...), @foreach(...)) are parsed as real Rust expressions and spliced directly into the generated function body - an undeclared variable is a genuine rustc compile error, not a custom check.

Derive Macros§

FormRequest
#[derive(FormRequest)]: generates an axum::extract::FromRequest impl that validates a form-urlencoded body against each field’s #[validate(...)] rules before the handler runs, returning a 422 with Laravel-shaped field errors on failure (Laravel’s FormRequest).
Model
#[derive(Model)]: generates TABLE/field-name constants, query(), all(), find(id), create(data), and delete(id) over larust-orm’s QueryBuilder, plus route model binding - an axum::extract::FromRequestParts impl so a handler can declare post: Post on a route like /posts/{post} and have it auto-resolved (404 if not found). Requires #[table("...")] on the struct and exactly one #[primary_key] field (currently must be i64). #[route_key("slug")] looks records up by that field instead of the primary key. #[timestamps] (Laravel’s $table->timestamps()) opts into automatic created_at/updated_at population - both must exist as i64 (Unix seconds) fields; create() stamps both, update() re-stamps updated_at only, and neither appears in the generated New* struct, matching Eloquent’s own “never set these yourself” behavior.