rivet_core/module.rs
1use std::sync::Arc;
2
3use rivet_foundation::{Config, ServiceProvider};
4use rivet_routing::Registry;
5
6use crate::error::RivetError;
7use crate::middleware::Middleware;
8
9/// Defines one composable unit of rivet behavior.
10///
11/// A module can participate in configuration, service-provider registration,
12/// route registration, and middleware registration during the build lifecycle.
13pub trait RivetModule: Send + Sync {
14 /// Stable module name used for logging and error context.
15 fn name(&self) -> &'static str;
16
17 /// Configure module-specific values before providers/routes are collected.
18 fn configure(&self, _config: &mut dyn Config) -> Result<(), RivetError> {
19 Ok(())
20 }
21
22 /// Return service providers contributed by this module.
23 ///
24 /// Providers are collected from all modules, then all are registered, then all are booted.
25 fn providers(&self) -> Vec<Box<dyn ServiceProvider>> {
26 vec![]
27 }
28
29 /// Register routes contributed by this module.
30 fn routes(&self, _routes: &mut Registry) -> Result<(), RivetError> {
31 Ok(())
32 }
33
34 /// Return middleware contributed by this module.
35 ///
36 /// Middleware is executed in registration order, then unwinds in reverse order.
37 fn middleware(&self) -> Vec<Arc<dyn Middleware>> {
38 vec![]
39 }
40}