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§
- Handler
Box - Live
State - The shared state between the launcher and dylib. The Container persists across reloads; routes get rebuilt every time the dylib registers itself.
- Registration
Manifest - 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).
- Registry
Generation - 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.
- Route
Entry - Route
Sink - The typed ABI a handler dylib exports. A
RouteSinkis 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§
Statics§
Functions§
- handler_
to_ method_ router - Build an axum
MethodRouterfor 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 --hotruntime to discover whether the host process is running in hot-reload mode.
Type Aliases§
- Handler
Fn - Type-erased async handler. The dylib returns a future-producing closure.