Skip to main content

AppBuilder

Struct AppBuilder 

Source
pub struct AppBuilder { /* private fields */ }
Expand description

Collects the root modules of an app, then validates, boots or runs it.

Implementations§

Source§

impl AppBuilder

Source

pub fn module(self, m: impl Module) -> Self

Adds a root module (imported by the implicit app root).

Source

pub fn override_value<T: ?Sized + Send + Sync + 'static>( self, value: Arc<T>, ) -> Self

Replaces the unnamed provider of T wherever it is registered with value (its factory never runs); registers value globally if no module provides T. Meant for tests and fakes.

Source

pub fn shutdown_timeout(self, d: Duration) -> Self

How long graceful shutdown waits for tracked tasks, and then for the on_shutdown hooks (default 30 s each).

Source

pub fn validate(&self) -> Result<GraphReport, BootErrors>

Validates the module graph without constructing any provider.

Source

pub fn plugin_report(&self) -> Result<PluginsReport, BootErrors>

Validates the module graph (as validate) and reports its plugins and what each of their modules adds. Nothing is built.

use navree_kernel::{Module, ModuleBuilder, Navree};

struct AnnouncementsModule;

impl Module for AnnouncementsModule {
    fn register(&self, m: &mut ModuleBuilder) {
        m.plugin(navree_kernel::plugin_info!(title = "Announcements"));
    }
}

fn main() -> Result<(), navree_kernel::BootErrors> {
    let report = Navree::app().module(AnnouncementsModule).plugin_report()?;
    println!("{report}");
    Ok(())
}
Source

pub async fn boot(self) -> Result<App, BootErrors>

Validates the graph, constructs every singleton (modules in dependency order), then runs on_init and on_bootstrap hooks.

Source§

impl AppBuilder

Source

pub async fn run_with_args(self, args: Vec<String>) -> Result<(), BoxError>

Runs a command line (without the program name):

  • check [--graph] validates the graph without constructing anything and prints a summary (or the module tree);
  • help / list prints the commands;
  • introspect [--json] validates the graph without constructing anything and prints it as JSON (GraphReport::to_json, with a "plugins" array as PluginsReport::to_json writes it);
  • plugins [--json] validates the graph without constructing anything and prints its plugins and what each adds (PluginsReport, or its JSON with --json); when the checks refuse the graph, it prints the listing first and fails with the refusals;
  • plugin:publish <plugin> [--tag views|locales|config|files] [--force] [--dry-run] validates the graph without constructing anything and copies the files the plugin (a namespace or a plugin’s name) ships into the app’s folders below the current directory, one line per file; an existing file is kept without --force, every path is checked before the first write, and --dry-run writes nothing. The config tag (and no --tag) runs the app’s config:publish --plugin <namespace>, when the app has that command, after the files are checked and before they are written, so a refusal from either leaves nothing written;
  • <name> [args...] boots the app, runs the registered command, then shuts the app down gracefully; a command marked offline skips the boot and the shutdown hooks;
  • no command runs serve if a module registers it, else help.

The built-ins plugins and plugin:publish yield: when a module of the app registers a command of one of these names, that command runs instead, with its arguments, and help and introspect no longer list the built-in. A module of a plugin that is not one of the framework’s own may not register a command of a built-in’s name.

Source

pub fn run(self) -> Result<(), BoxError>

Runs the app from std::env::args on a new multi-threaded runtime. Ctrl-C (and SIGTERM on Unix) cancels the shutdown token, so serve and workers stop; the app then shuts down within the shutdown timeout.

Trait Implementations§

Source§

impl Debug for AppBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AppBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more