Skip to main content

serenade_kernel/
bundle.rs

1//! Bundle registration contract used during kernel compile and boot.
2
3use crate::KernelError;
4
5/// Composition unit registered on a [`Kernel`](crate::Kernel).
6///
7/// Bundles declare [`Self::dependencies`]; the kernel topologically sorts them
8/// before `build` / `boot` so dependents run after their dependencies.
9/// Default implementations are no-ops so an empty bundle is valid.
10///
11/// `BundleInterface` is the Symfony-shaped name; [`Bundle`] is the same trait.
12pub trait BundleInterface: Send + Sync {
13    /// Stable unique name used for duplicate detection and error reports.
14    fn name(&self) -> &'static str;
15
16    /// Bundle names that must compile and boot before this one.
17    ///
18    /// Empty by default. Unknown names and cycles fail at [`crate::Kernel::compile`].
19    fn dependencies(&self) -> &'static [&'static str] {
20        &[]
21    }
22
23    /// Compile-time wiring (register services on the DI container).
24    ///
25    /// # Errors
26    ///
27    /// Return [`KernelError`] when the bundle cannot be compiled.
28    fn build(&self) -> Result<(), KernelError> {
29        Ok(())
30    }
31
32    /// Runtime warmup after the kernel has compiled.
33    ///
34    /// # Errors
35    ///
36    /// Return [`KernelError`] when the bundle cannot start.
37    fn boot(&self) -> Result<(), KernelError> {
38        Ok(())
39    }
40
41    /// Ordered teardown after [`Kernel::shutdown`](crate::Kernel::shutdown).
42    ///
43    /// # Errors
44    ///
45    /// Return [`KernelError`] when teardown fails.
46    fn shutdown(&self) -> Result<(), KernelError> {
47        Ok(())
48    }
49}
50
51/// Alias for [`BundleInterface`] (Symfony `Bundle` naming habit).
52pub use BundleInterface as Bundle;