Skip to main content

Crate slabs

Crate slabs 

Source
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, and webhooks.
  • Top-level re-exports: id, AppConfig, AppManifest, JobMeta, RouteMeta, SlabError, SlabResult, build_router, AppCtx, JobDef, JobRegistry, RateLimiter, ScheduleDef, and SlabDef.
  • prelude: single import (use slabs::prelude::*;) for slab and job files.
  • discover_slabs!: macro that includes $OUT_DIR/discovered_slabs.rs generated by slabs-build.
  • SlabsApp: boots AppCtx, runs migrations, builds the router, and serves HTTP plus background workers.
  • init_tracing: initializes tracing_subscriber with RUST_LOG and optional JSON output.

§Agent invariants

  • Invoke slabs::discover_slabs!(); once in the application crate’s src/lib.rs. It generates discovered_slabs, discovered_jobs, collect_slabs(), and collect_jobs().
  • Import use slabs::prelude::*; inside slab files instead of wiring sub-crates individually.
  • Boot the app with SlabsApp::boot, passing a sqlx::migrate::Migrator, collect_slabs(), and collect_jobs().
  • Attach recurring jobs with SlabsApp::with_schedules before calling SlabsApp::serve.
  • SlabsApp::serve spawns background job workers and schedules, binds config.bind_addr, and shuts down cleanly on SIGINT or SIGTERM.
  • Call init_tracing at the top of main(). Set SLABS_LOG_FORMAT=json for structured JSON logs and RUST_LOG to 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... or usr_01j...).
position
Fractional list positioning helpers for O(1) single-row reordering.
prelude
Standard Slabs types, helpers, and maud HTML 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_* and DATABASE_URL environment 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.
AuditEntry
Persisted audit event row stored in slabs_audit_log.
AuditLog
Transactional audit log backed by the slabs_audit_log system table.
CursorPage
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 discovered JobDef handlers.
Pagination
Query parameters for cursor-based (keyset) pagination.
RateLimiter
Explicit in-memory fixed-window rate limiter for auth and sensitive slabs.
RouteMeta
Machine-readable HTTP route metadata emitted by /_slabs/manifest and slabs manifest.
ScheduleDef
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.
SlabsApp
High-level boot entry point for a Slabs application.
Validate
Multi-field procedural validation builder for transaction scripts.

Enums§

FlashKind
Severity level for a one-shot Flash banner message.
SlabError
Unified HTTP error type returned by every transaction script and background job.

Functions§

build_router
Assemble the full axum::Router from discovered slabs, built-in endpoints, and middleware.
fingerprint
Compute a lowercase SHA-256 hex digest over NUL-separated string parts.
init_tracing
Initialize tracing_subscriber using RUST_LOG (defaulting to info,tower_http=info,sqlx=warn).

Type Aliases§

SlabResult
Result alias using SlabError as the error type.