pub trait Module:
Send
+ Sync
+ 'static {
// Required method
fn name(&self) -> &'static str;
// Provided methods
fn routes(&self) -> Routes { ... }
fn migrations(&self) -> &'static [Migration] { ... }
fn register(&self, _app: &mut Registry) { ... }
}Expand description
A self-contained piece of an application: its routes and migrations, and later its jobs, policies and views.
pub struct Products;
impl Module for Products {
fn name(&self) -> &'static str { "products" }
fn routes(&self) -> Routes {
Routes::new()
.get("/products", index).name("products.index")
.get("/products/{id}", show).name("products.show")
}
}Required Methods§
Provided Methods§
Sourcefn migrations(&self) -> &'static [Migration]
fn migrations(&self) -> &'static [Migration]
Migrations this module owns, e.g. renox::migrations!("src/app/products/migrations").
Sourcefn register(&self, _app: &mut Registry)
fn register(&self, _app: &mut Registry)
Registers the module’s jobs, event listeners and scheduled tasks.
fn register(&self, app: &mut Registry) {
app.job::<SendReceipt>()
.listen(|e: OrderPlaced, state| async move {
state.dispatch(SendReceipt { order_id: e.order_id }).await?;
Ok(())
});
app.schedule().daily_at("02:00", "close-day", close_day);
}Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".