Expand description
Luxid — a convention-over-configuration web framework for Rust.
ⓘ
use luxid::prelude::*;
pub struct UsersController;
#[luxid::controller]
impl UsersController {
async fn index(ctx: HttpContext) -> Result<Response> {
let page = ctx.request.input::<u32>("page")?.unwrap_or(1);
ctx.response.ok(serde_json::json!({ "page": page }))
}
}
#[tokio::main]
async fn main() -> luxid::Result<()> {
App::new()
.routes(|r| {
r.group("/api/v1", |r| {
r.get("/users", UsersController::index);
});
})
.run()
.await
}Re-exports§
Modules§
- adapter
- The salvo bridge. This is the only module in Luxid that knows salvo exists.
- app
- Application assembly and startup.
- auth
- Authentication: password hashing, tokens, and the request’s identity.
- cli
- The application command line.
- container
- The service container.
- context
HttpContext— the single argument every Luxid action receives.- error
- The single error type every Luxid action can
?on. - http
- inertia
- The server half of the Inertia.js protocol.
- migration
- Migrations.
- mw
- The middleware chain.
- prelude
- router
- Explicit route registration.
- session
- Server-side sessions.
Structs§
- App
- Auth
- The authentication state of the current request.
- Config
- A read-only view of the application’s configuration. Cheap to clone.
- Container
- A handle onto the application’s services. Cheap to clone.
- Cookie
- A cookie to send with a response.
- Db
- The data layer.
The application’s database, registered as a singleton in
providers(). - Extensions
- A typed, request-scoped bag.
- Factory
Builder - The data layer. A pending set of rows.
- Hash
- Argon2id password hashing.
- Http
Context - Everything an action needs, owned.
- Identity
- Who the current request is, plus whatever claims came with them.
- Inertia
- Enables the Inertia protocol for a route group.
- Inertia
Request - The request’s Inertia state, set by the
Inertiamiddleware. - Jwt
- HS256 token signing and verification.
- Memory
Store - An in-process store.
- Migration
State - Whether a migration has run.
- Next
- The remainder of the chain, handed to each middleware.
- Paginated
- The data layer. A page of results. Serializes in the shape Laravel’s paginator produces, so existing clients need no translation.
- Params
- Route parameters captured from the path (
/users/{id}). - Providers
- Declarative bindings, assembled in
src/app.rsand frozen into aContainerat boot. - Query
- The data layer.
- Relations
- The data layer. The relations loaded onto one model instance.
- Request
- Response
- Route
- Router
- Session
- The request’s session.
- Validation
Errors - Field-keyed validation failures, aggregated so a request reports every problem at once rather than one per round trip.
- With
Database - The data layer. Middleware that puts the application’s database in scope for the request.
- With
Rollback Database - The data layer.
As
WithDatabase, but every request runs in a transaction that is rolled back afterwards. Intended for tests, never for production.
Enums§
- Body
- Error
- Lifetime
- Method
#[non_exhaustive]is load-bearing, for the same reason it is onHttpContext: it forces downstream crates to write a_arm, so adding a verb — HEAD, TRACE, whatever a future protocol needs — is permanently non-breaking. AddingOptionsfor CORS preflight was the warning shot.- Same
Site
Traits§
- Action
- The terminal step of a chain: a controller action.
- Column
Ref - A column a query can filter or order by.
- Factory
- The data layer. The typical shape of a row.
- Hooks
- The data layer.
Lifecycle callbacks, generated by
#[derive(Model)]. - Json
Schema - Re-exported so applications can derive schemas without declaring schemars. A type which can be described as a JSON Schema document.
- Middleware
- A step in the chain.
- Record
- The data layer.
Read operations on a stored row, implemented by
#[derive(Model)]. - Relatable
- The data layer.
A model that declares relations. Implemented by
#[luxid::model]. - Session
Store - Where session data lives.
- Validate
- Implemented by
#[derive(Validate)].
Functions§
- delete_
by_ id - Delete a row by primary key. Returns whether anything was removed.
- insert
- Insert an active model and return the stored row, running the model’s create hooks around the write.
- insert_
without_ hooks - Insert without running hooks.
- set_
strict_ relations - The data layer. Turn unloaded-relation access into an error (the default in debug builds).
- strict_
relations - The data layer.
- update
- Persist changes to an active model and return the stored row, running the model’s update hooks around the write.
- validate
- Run every rule and aggregate the failures into a single 422.
Type Aliases§
- BoxFuture
- Result
- Session
Data - Everything stored against one session id.
Attribute Macros§
- controller
- Turn an inherent
implblock into routable actions. - middleware
- Implement
Middlewarefrom an inherentasync fn handle(&self, ctx: HttpContext, next: Next) -> Result<Response>. - model
- Declare a model’s relations.
- test
- A test that leaves the database as it found it.
Derive Macros§
- Json
Schema - Re-exported so applications can derive schemas without declaring schemars.
Derive macro for
JsonSchematrait. - Model
- Derive model operations and typed columns for a SeaORM entity model.
- Validate
- Derive form-request validation.