Skip to main content

Kernel

Struct Kernel 

Source
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

Source

pub fn new(environment: Environment) -> Self

Creates a kernel in KernelPhase::Created.

Debug defaults to Environment::is_debug.

Source

pub const fn with_debug(self, debug: bool) -> Self

Overrides the debug flag. Call before Self::compile.

Source

pub const fn environment(&self) -> &Environment

Runtime environment.

Source

pub const fn debug(&self) -> bool

Effective debug flag.

Source

pub const fn phase(&self) -> KernelPhase

Current lifecycle phase.

Source

pub fn bundle_names(&self) -> Vec<&'static str>

Bundle names in effective order.

Before compile: registration order. After compile: dependency order.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for Kernel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.