Skip to main content

Crate luxid

Crate luxid 

Source
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§

pub use sea_orm;
pub use self;

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.
FactoryBuilder
The data layer. A pending set of rows.
Hash
Argon2id password hashing.
HttpContext
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.
InertiaRequest
The request’s Inertia state, set by the Inertia middleware.
Jwt
HS256 token signing and verification.
MemoryStore
An in-process store.
MigrationState
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.rs and frozen into a Container at 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.
ValidationErrors
Field-keyed validation failures, aggregated so a request reports every problem at once rather than one per round trip.
WithDatabase
The data layer. Middleware that puts the application’s database in scope for the request.
WithRollbackDatabase
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 on HttpContext: it forces downstream crates to write a _ arm, so adding a verb — HEAD, TRACE, whatever a future protocol needs — is permanently non-breaking. Adding Options for CORS preflight was the warning shot.
SameSite

Traits§

Action
The terminal step of a chain: a controller action.
ColumnRef
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)].
JsonSchema
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].
SessionStore
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
SessionData
Everything stored against one session id.

Attribute Macros§

controller
Turn an inherent impl block into routable actions.
middleware
Implement Middleware from an inherent async 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§

JsonSchema
Re-exported so applications can derive schemas without declaring schemars. Derive macro for JsonSchema trait.
Model
Derive model operations and typed columns for a SeaORM entity model.
Validate
Derive form-request validation.