Expand description
Event System and Lifecycle Hooks
Provides an in-process publish/subscribe event bus and lifecycle hooks for the RustAPI application.
§Lifecycle Hooks
ⓘ
use rustapi_core::RustApi;
RustApi::new()
.on_start(|| async {
println!("Server started!");
})
.on_shutdown(|| async {
println!("Server shutting down...");
})
.run("127.0.0.1:8080")
.await§Event Bus
ⓘ
use rustapi_core::events::EventBus;
use rustapi_core::State;
let bus = EventBus::new();
// Subscribe to events
bus.on("user.created", |payload: &str| {
println!("User created: {}", payload);
});
// In a handler, emit events
async fn create_user(State(bus): State<EventBus>) -> impl IntoResponse {
bus.emit("user.created", "user_123");
"created"
}Structs§
- Event
Bus - In-process publish/subscribe event bus