Expand description
§diode-base
Base functionality and utilities for diode applications, providing essential building blocks for creating robust, configurable, and maintainable services.
This crate extends the core diode dependency injection framework with practical utilities for real-world applications including configuration management, daemon services, command-line interfaces, and application lifecycle management.
§Core Components
- Configuration System: Type-safe configuration loading and merging from multiple sources
- Daemon Framework: Long-running background services with graceful shutdown
- Command System: CLI framework with subcommands and dependency injection
- Bundle Management: Modular application component grouping
- Tracing Integration: Structured logging and observability
- Dynamic Configuration: Runtime configuration updates and hot-reloading
§Quick Start
use diode::App;
use diode_base::{RunMainExt, AddCommandExt, Command};
use std::process::ExitCode;
use std::sync::Arc;
use clap::Command as ClapCommand;
struct HelloCommand;
impl Command for HelloCommand {
fn command() -> ClapCommand {
ClapCommand::new("hello").about("Says hello")
}
async fn main(_app: Arc<App>, _matches: clap::ArgMatches) -> ExitCode {
println!("Hello from diode!");
ExitCode::SUCCESS
}
}
#[tokio::main]
async fn main() -> ExitCode {
App::builder()
.add_command::<HelloCommand>()
.run_main()
.await
}§Configuration Example
use diode::App;
use diode_base::Config;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct DatabaseConfig {
host: String,
port: u16,
}
let app = App::builder()
.add_component(Config::new().with("database", DatabaseConfig {
host: "localhost".to_string(),
port: 5432,
}))
.build()
.await?;
let config = app.get_component_ref::<Config>().unwrap();
let db_config = config.get::<DatabaseConfig>("database")?;
println!("Database: {}:{}", db_config.host, db_config.port);§Features
macros(default): Enables procedural macros for simplified configuration and service definitions
Modules§
Macros§
Structs§
- Cancellation
Token - Cooperative cancellation token used to signal daemons to shut down. A token which can be used to signal a cancellation request to one or more tasks.
- Config
- Config
Command - Built-in config command that displays the current configuration.
- Dynamic
Config - Main dynamic configuration store
- Dynamic
Config Config - Configuration for dynamic config system
- Dynamic
Config File - File-based dynamic configuration provider
- Dynamic
Config File Config - Dynamic
Config Updater - Updater interface for providers to update configuration
- Dynamic
Value - Dynamic
Value Guard - Metrics
- Metrics
Config - Metrics
Otlp Exporter Config - Server
Command - Built-in server command that runs all registered daemons.
- Tracing
- Tracing
Config - Tracing
Otlp Exporter Config
Traits§
- AddCommand
Ext - Extension trait for
AppBuilderto add command registration methods. - AddDaemon
Ext - Registers concrete
Daemoninstances on the application. - AddDaemon
Service Ext - Registers daemons resolved from the dependency-injection container.
- AddDynamic
Config Ext - Bundle
Ext - Command
- Trait for defining CLI commands that can access the application’s dependency container.
- Config
Section - Daemon
- A long-running background task managed by the application.
- Dynamic
Config Service - Trait for dynamic configuration providers
- RunDaemons
Ext - Runs every registered
Daemonuntil shutdown. - RunMain
Ext - Extension trait for
AppBuilderto run the main CLI application.