Expand description
Batteries-included Transaction Script web framework in Rust.
§What this crate owns
- Facade re-exports of every Slabs sub-crate:
assets,auth,cache,core,db,html,http,jobs,mail,realtime,storage,test, andwebhooks. - Top-level re-exports:
id,AppConfig,AppManifest,JobMeta,RouteMeta,SlabError,SlabResult,build_router,AppCtx,JobDef,JobRegistry,RateLimiter,ScheduleDef, andSlabDef. prelude: single import (use slabs::prelude::*;) for slab and job files.discover_slabs!: macro that includes$OUT_DIR/discovered_slabs.rsgenerated byslabs-build.SlabsApp: bootsAppCtx, runs migrations, builds the router, and serves HTTP plus background workers.init_tracing: initializestracing_subscriberwithRUST_LOGand optional JSON output.
§Agent invariants
- Invoke
slabs::discover_slabs!();once in the application crate’ssrc/lib.rs. It generatesdiscovered_slabs,discovered_jobs,collect_slabs(), andcollect_jobs(). - Import
use slabs::prelude::*;inside slab files instead of wiring sub-crates individually. - Boot the app with
SlabsApp::boot, passing asqlx::migrate::Migrator,collect_slabs(), andcollect_jobs(). - Attach recurring jobs with
SlabsApp::with_schedulesbefore callingSlabsApp::serve. SlabsApp::servespawns background job workers and schedules, bindsconfig.bind_addr, and shuts down cleanly onSIGINTorSIGTERM.- Call
init_tracingat the top ofmain(). SetSLABS_LOG_FORMAT=jsonfor structured JSON logs andRUST_LOGto override the default filter (info,tower_http=info,sqlx=warn).
§Example
use slabs::{AppConfig, SlabsApp};
// In src/lib.rs, after calling slabs_build::discover() in build.rs:
// slabs::discover_slabs!();
// pub static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!("./migrations");
async fn run(migrator: &sqlx::migrate::Migrator) -> slabs::SlabResult<()> {
slabs::init_tracing();
let config = AppConfig::from_env("my_app");
let app = SlabsApp::boot(config, migrator, vec![], vec![]).await?;
app.serve().await
}Re-exports§
pub use slabs_assets as assets;pub use slabs_auth as auth;pub use slabs_cache as cache;pub use slabs_core as core;pub use slabs_db as db;pub use slabs_html as html;pub use slabs_http as http;pub use slabs_jobs as jobs;pub use slabs_mail as mail;pub use slabs_realtime as realtime;pub use slabs_storage as storage;pub use slabs_test as test;pub use slabs_webhooks as webhooks;
Modules§
- id
- Prefix-tagged, time-sortable ULID generator (for example
msg_01j...orusr_01j...). - position
- Fractional list positioning helpers for O(1) single-row reordering.
- prelude
- Standard Slabs types, helpers, and
maudHTML macros re-exported for slab and job files. - slug
- URL slug generation helpers.
Macros§
- discover_
slabs - Include the compile-time discovered transaction scripts and background jobs generated by
slabs_build::discover().
Structs§
- AppConfig
- Runtime configuration loaded from
SLABS_*andDATABASE_URLenvironment variables. - AppCtx
- Shared runtime context passed to every HTTP slab handler and background job.
- AppManifest
- Complete JSON manifest of an application’s discovered HTTP routes and background jobs.
- Audit
Entry - Persisted audit event row stored in
slabs_audit_log. - Audit
Log - Transactional audit log backed by the
slabs_audit_logsystem table. - Cursor
Page - One page of cursor-paginated results.
- Flash
- One-shot feedback message carried across a redirect in a signed cookie.
- JobDef
- Self-contained Background Job Transaction Script definition returned by
pub fn job() -> JobDef. - JobMeta
- Machine-readable metadata describing a registered background job.
- JobRegistry
- Dispatches
SQLite-queued jobs to discoveredJobDefhandlers. - Pagination
- Query parameters for cursor-based (keyset) pagination.
- Rate
Limiter - Explicit in-memory fixed-window rate limiter for auth and sensitive slabs.
- Route
Meta - Machine-readable HTTP route metadata emitted by
/_slabs/manifestandslabs manifest. - Schedule
Def - Recurring maintenance schedule that enqueues a registered job on a fixed interval.
- SlabDef
- Self-contained HTTP Transaction Script definition returned by
pub fn slab() -> SlabDef. - Slabs
App - High-level boot entry point for a Slabs application.
- Validate
- Multi-field procedural validation builder for transaction scripts.
Enums§
- Flash
Kind - Severity level for a one-shot
Flashbanner message. - Slab
Error - Unified HTTP error type returned by every transaction script and background job.
Functions§
- build_
router - Assemble the full
axum::Routerfrom discovered slabs, built-in endpoints, and middleware. - fingerprint
- Compute a lowercase SHA-256 hex digest over NUL-separated string parts.
- init_
tracing - Initialize
tracing_subscriberusingRUST_LOG(defaulting toinfo,tower_http=info,sqlx=warn).
Type Aliases§
- Slab
Result - Result alias using
SlabErroras the error type.