pub struct AppBuilder { /* private fields */ }Expand description
Builder for constructing an App with registered services, plugins, and components.
The AppBuilder provides a fluent API for configuring an application before building it.
It handles dependency resolution, plugin initialization, and component registration in the
correct order based on declared dependencies.
§Examples
use diode::{App, Service, StdError, AddServiceExt};
use std::sync::Arc;
struct DatabaseService;
struct ApiService;
impl Service for DatabaseService {
type Handle = Arc<Self>;
async fn build(_app: &diode::AppBuilder) -> Result<Self::Handle, StdError> {
Ok(Arc::new(Self))
}
}
impl Service for ApiService {
type Handle = Arc<Self>;
async fn build(_app: &diode::AppBuilder) -> Result<Self::Handle, StdError> {
Ok(Arc::new(Self))
}
}
let app = App::builder()
.add_service::<DatabaseService>()
.add_service::<ApiService>()
.add_component("config_value".to_string())
.build()
.await?;Implementations§
Source§impl AppBuilder
impl AppBuilder
Sourcepub fn add_plugin<T>(&mut self, plugin: T) -> &mut Selfwhere
T: Plugin + 'static,
pub fn add_plugin<T>(&mut self, plugin: T) -> &mut Selfwhere
T: Plugin + 'static,
Adds a plugin to the application builder.
Plugins are initialized during the build process in dependency order. Each plugin type can only be added once.
§Type Parameters
T- The plugin type to add. Must implementPlugin + 'static.
§Arguments
plugin- The plugin instance to add.
§Returns
Returns &mut Self for method chaining.
§Panics
Panics if a plugin of the same type has already been added.
§Examples
use diode::{App, Plugin, Dependencies, StdError};
struct MyPlugin;
impl Plugin for MyPlugin {
async fn build(&self, _app: &mut diode::AppBuilder) -> Result<(), StdError> {
Ok(())
}
}
let app = App::builder()
.add_plugin(MyPlugin)
.build()
.await?;Sourcepub fn has_plugin<T>(&self) -> boolwhere
T: Plugin + 'static,
pub fn has_plugin<T>(&self) -> boolwhere
T: Plugin + 'static,
Sourcepub fn add_component<T>(&mut self, component: T) -> &mut Self
pub fn add_component<T>(&mut self, component: T) -> &mut Self
Adds a component directly to the application builder.
Components added this way are immediately available and do not require dependency resolution. Each component type can only be added once.
§Type Parameters
T- The component type to add. Must implementSend + Sync + 'static.
§Arguments
component- The component instance to add.
§Returns
Returns &mut Self for method chaining.
§Panics
Panics if a component of the same type has already been added.
§Examples
use diode::App;
let app = App::builder()
.add_component(42i32)
.add_component("configuration".to_string())
.build()
.await?;
assert_eq!(app.get_component::<i32>(), Some(42));Sourcepub fn get_component<T>(&self) -> Option<T>
pub fn get_component<T>(&self) -> Option<T>
Sourcepub fn has_component<T>(&self) -> bool
pub fn has_component<T>(&self) -> bool
Sourcepub fn get_component_ref<T>(&self) -> Option<&T>
pub fn get_component_ref<T>(&self) -> Option<&T>
Sourcepub fn get_component_mut<T>(&mut self) -> Option<&mut T>
pub fn get_component_mut<T>(&mut self) -> Option<&mut T>
pub async fn build(&mut self) -> Result<App, AppError>
Trait Implementations§
Source§impl AddServiceExt for AppBuilder
impl AddServiceExt for AppBuilder
Source§impl ExtractRef<AppBuilder> for AppBuilder
impl ExtractRef<AppBuilder> for AppBuilder
Source§fn extract_ref(app: &AppBuilder) -> Result<&AppBuilder, AppError>
fn extract_ref(app: &AppBuilder) -> Result<&AppBuilder, AppError>
T from the application builder. Read more