Skip to main content

diode_base/
lib.rs

1//! # diode-base
2//!
3//! Base functionality and utilities for diode applications, providing essential
4//! building blocks for creating robust, configurable, and maintainable services.
5//!
6//! This crate extends the core diode dependency injection framework with
7//! practical utilities for real-world applications including configuration management,
8//! daemon services, command-line interfaces, and application lifecycle management.
9//!
10//! ## Core Components
11//!
12//! - **Configuration System**: Type-safe configuration loading and merging from multiple sources
13//! - **Daemon Framework**: Long-running background services with graceful shutdown
14//! - **Command System**: CLI framework with subcommands and dependency injection
15//! - **Bundle Management**: Modular application component grouping
16//! - **Tracing Integration**: Structured logging and observability
17//! - **Dynamic Configuration**: Runtime configuration updates and hot-reloading
18//!
19//! ## Quick Start
20//!
21//! ```rust,no_run
22//! use diode::App;
23//! use diode_base::{RunMainExt, AddCommandExt, Command};
24//! use std::process::ExitCode;
25//! use std::sync::Arc;
26//! use clap::Command as ClapCommand;
27//!
28//! struct HelloCommand;
29//!
30//! impl Command for HelloCommand {
31//!     fn command() -> ClapCommand {
32//!         ClapCommand::new("hello").about("Says hello")
33//!     }
34//!
35//!     async fn main(_app: Arc<App>, _matches: clap::ArgMatches) -> ExitCode {
36//!         println!("Hello from diode!");
37//!         ExitCode::SUCCESS
38//!     }
39//! }
40//!
41//! #[tokio::main]
42//! async fn main() -> ExitCode {
43//!     App::builder()
44//!         .add_command::<HelloCommand>()
45//!         .run_main()
46//!         .await
47//! }
48//! ```
49//!
50//! ## Configuration Example
51//!
52//! ```rust
53//! use diode::App;
54//! use diode_base::Config;
55//! use serde::{Deserialize, Serialize};
56//!
57//! #[derive(Debug, Serialize, Deserialize)]
58//! struct DatabaseConfig {
59//!     host: String,
60//!     port: u16,
61//! }
62//!
63//! # async fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
64//! let app = App::builder()
65//!     .add_component(Config::new().with("database", DatabaseConfig {
66//!         host: "localhost".to_string(),
67//!         port: 5432,
68//!     }))
69//!     .build()
70//!     .await?;
71//!
72//! let config = app.get_component_ref::<Config>().unwrap();
73//! let db_config = config.get::<DatabaseConfig>("database")?;
74//! println!("Database: {}:{}", db_config.host, db_config.port);
75//! # Ok(())
76//! # }
77//! ```
78//!
79//! ## Features
80//!
81//! - `macros` (default): Enables procedural macros for simplified configuration and service definitions
82
83mod bundle;
84mod command;
85mod config;
86mod daemon;
87mod defer;
88mod dynamic_config;
89mod dynamic_config_file;
90mod metrics;
91mod tracing;
92
93pub mod testing;
94
95pub use bundle::*;
96pub use command::*;
97pub use config::*;
98pub use daemon::*;
99pub use defer::*;
100pub use dynamic_config::*;
101pub use dynamic_config_file::*;
102pub use metrics::*;
103pub use tracing::*;
104
105#[cfg(feature = "macros")]
106pub use diode_base_macros::*;
107
108pub use async_trait::async_trait;