pub trait BackboneModule: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn version(&self) -> &'static str;
fn migrations_path(&self) -> Option<PathBuf>;
// Provided methods
fn dependencies(&self) -> Vec<&'static str> { ... }
fn seeds_path(&self) -> Option<PathBuf> { ... }
fn on_boot<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn migration_info(&self) -> Option<MigrationInfo> { ... }
fn seed_info(&self) -> Option<SeedInfo> { ... }
}Expand description
Trait for Backbone modules with migration support
Implement this trait to register a module with the Backbone framework. The framework will automatically discover and run migrations for all registered modules in dependency order.
§Example
use backbone_core::module::BackboneModule;
use std::path::PathBuf;
pub struct BersihirModule;
impl BackboneModule for BersihirModule {
fn name(&self) -> &'static str { "bersihir" }
fn version(&self) -> &'static str { env!("CARGO_PKG_VERSION") }
fn dependencies(&self) -> Vec<&'static str> {
vec!["sapiens"] // Depends on user module
}
fn migrations_path(&self) -> Option<PathBuf> {
Some(PathBuf::from("libs/modules/bersihir/migrations"))
}
}Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Returns the unique identifier for this module
This should be a short, lowercase name like “bersihir”, “sapiens”, etc.
Sourcefn version(&self) -> &'static str
fn version(&self) -> &'static str
Returns the version of this module
Typically uses env!("CARGO_PKG_VERSION") to get from Cargo.toml
Sourcefn migrations_path(&self) -> Option<PathBuf>
fn migrations_path(&self) -> Option<PathBuf>
Returns the path to this module’s migrations directory
Path should be relative to the repository root.
Return None if the module has no migrations.
§Example paths:
libs/modules/bersihir/migrationslibs/modules/sapiens/migrations
Provided Methods§
Sourcefn dependencies(&self) -> Vec<&'static str>
fn dependencies(&self) -> Vec<&'static str>
Returns the list of module names this module depends on
Dependencies are used to determine migration order. A module’s migrations will only run after all its dependencies have been migrated.
§Returns
A list of module names (e.g., vec!["sapiens", "bucket"])
Sourcefn seeds_path(&self) -> Option<PathBuf>
fn seeds_path(&self) -> Option<PathBuf>
Returns the path to this module’s seeds directory (optional)
Seeds are used to populate the database with initial data.
Sourcefn on_boot<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_boot<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Called after migrations are run to initialize the module
Use this for any setup that needs to happen after the database is ready but before the application starts serving requests.
Sourcefn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Called when the application is shutting down
Use this for cleanup tasks.
Sourcefn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Perform a health check for this module
Returns true if the module is healthy and ready to serve requests.
Sourcefn migration_info(&self) -> Option<MigrationInfo>
fn migration_info(&self) -> Option<MigrationInfo>
Get migration info for this module
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".