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) -> Kernel
pub fn new(environment: Environment) -> Kernel
Creates a kernel in KernelPhase::Created.
Debug defaults to Environment::is_debug.
Sourcepub const fn with_debug(self, debug: bool) -> Kernel
pub const fn with_debug(self, debug: bool) -> Kernel
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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Kernel
impl !UnwindSafe for Kernel
impl Forget for Kernel
impl Freeze for Kernel
impl Move for Kernel
impl Send for Kernel
impl Sync for Kernel
impl Unpin for Kernel
impl UnsafeUnpin for Kernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more