pub struct Kernel { /* private fields */ }Expand description
Application kernel: environment, bundle order, and lifecycle.
§Examples
use serenade_kernel::{App, Application, Environment, KernelPhase};
let mut app = App::new(Environment::Test);
app.boot().expect("boot");
assert_eq!(app.kernel().phase(), KernelPhase::Booted);
app.shutdown().expect("shutdown");
assert_eq!(app.kernel().phase(), KernelPhase::Shutdown);Implementations§
Source§impl Kernel
impl Kernel
Sourcepub fn new(environment: Environment) -> Self
pub fn new(environment: Environment) -> Self
Creates a kernel in KernelPhase::Created.
Debug defaults to Environment::is_debug.
Sourcepub const fn with_debug(self, debug: bool) -> Self
pub const fn with_debug(self, debug: bool) -> Self
Overrides the debug flag. Call before Self::compile.
Sourcepub const fn environment(&self) -> &Environment
pub const fn environment(&self) -> &Environment
Runtime environment.
Sourcepub const fn phase(&self) -> KernelPhase
pub const fn phase(&self) -> KernelPhase
Current lifecycle phase.
Sourcepub fn bundle_names(&self) -> Vec<&'static str>
pub fn bundle_names(&self) -> Vec<&'static str>
Bundle names in effective order.
Before compile: registration order. After compile: dependency order.
Sourcepub fn register_bundle(
&mut self,
bundle: impl BundleInterface + 'static,
) -> Result<(), KernelError>
pub fn register_bundle( &mut self, bundle: impl BundleInterface + 'static, ) -> Result<(), KernelError>
Registers a bundle. Must run while the kernel is KernelPhase::Created.
§Errors
Returns KernelError::InvalidState after compile, or
KernelError::DuplicateBundle when bundle.name() is already registered.
Sourcepub fn compile(&mut self) -> Result<(), KernelError>
pub fn compile(&mut self) -> Result<(), KernelError>
Sorts bundles by dependencies, then runs BundleInterface::build in that order.
§Errors
Returns KernelError::InvalidState unless the kernel is KernelPhase::Created,
or a dependency-graph / bundle build error.
Sourcepub fn boot(&mut self) -> Result<(), KernelError>
pub fn boot(&mut self) -> Result<(), KernelError>
Compiles if needed, then runs BundleInterface::boot in dependency order.
§Errors
Returns KernelError::InvalidState when already booted or shut down.
Sourcepub fn shutdown(&mut self) -> Result<(), KernelError>
pub fn shutdown(&mut self) -> Result<(), KernelError>
Runs BundleInterface::shutdown in reverse dependency order.
§Errors
Returns KernelError::InvalidState unless the kernel is KernelPhase::Booted.