Skip to main content

Crate anvil_dev

Crate anvil_dev 

Source
Expand description

Anvilforge dev-mode hot-reload runtime.

Wraps the structural complexity of dylib hot-patching behind a single typed ABI. User handler crates expose one function:

// in handlers crate src/lib.rs
use anvilforge::prelude::*;

#[no_mangle]
pub extern "Rust" fn anvil_register_routes(r: &mut RouteSink) {
    r.route("GET", "/posts", routes::list_posts);
    r.route("POST", "/posts", routes::create_post);
}

The host binary uses anvil_dev::live_server(...) (or implicitly via anvil dev --hot) to load this function, watch the dylib for changes, and re-register routes on reload. The framework Container stays alive across reloads — DB pools, sessions, Spark snapshots, WebSocket subscribers all survive.

Compromise budget:

  • State INSIDE the dylib (statics, thread-locals, lazy_static) is reset on reload. Move state into the framework Container if you need it to persist.
  • ABI changes (signature of a registered route) require a full restart. The launcher detects this and prints a clean message.
  • Debuggers may lose breakpoint state across reloads; see README.

Re-exports§

pub use http;
pub use parking_lot;

Structs§

HandlerBox
LiveState
The shared state between the launcher and dylib. The Container persists across reloads; routes get rebuilt every time the dylib registers itself.
RegistrationManifest
One-time payload the dylib sends to the host on registration, carrying metadata about what it registered. Useful for diagnostics + auto-restart detection (we can spot ABI mismatches by checking version + entry count).
RegistryGeneration
A re-loadable registry index used so reloads can replace previously registered entries by class/path key (when needed). Not strictly required for routes (we just rebuild the whole table) but kept here for parity with other inventory-driven anvil registries.
RouteEntry
RouteSink
The typed ABI a handler dylib exports. A RouteSink is handed to the dylib on each (re)load; the dylib calls .route(...) once per route it owns. Routes registered on reload replace the previous set atomically.

Constants§

ABI_VERSION

Statics§

GENERATION

Functions§

handler_to_method_router
Build an axum MethodRouter for a single registered route. Used by the runtime to construct the live router after each reload.
is_hot_mode
Helper used by the anvil dev --hot runtime to discover whether the host process is running in hot-reload mode.

Type Aliases§

HandlerFn
Type-erased async handler. The dylib returns a future-producing closure.