Skip to main content

hiver_config/
lib.rs

1#![allow(clippy::expect_used)]
2//! Hiver Config - Configuration management module
3//! Hiver配置 - 配置管理模块
4//!
5//! # Equivalent to Spring Boot / 等价于 Spring Boot
6//!
7//! - `@ConfigurationProperties` - `PropertiesConfig`
8//! - `@Value` - Value extractor
9//! - `Environment` - Environment
10//! - `PropertySource` - `PropertySource`
11//! - `@Profile` - Profile
12//! - `ConfigFileApplicationListener` - `ConfigLoader`
13//!
14//! # Example / 示例
15//!
16//! ```rust,no_run,ignore
17//! use hiver_config::{Config, PropertiesConfig};
18//! use serde::Deserialize;
19//!
20//! #[derive(PropertiesConfig, Deserialize)]
21//! #[prefix = "app.datasource"]
22//! struct DataSourceConfig {
23//!     url: String,
24//!     username: String,
25//!     password: String,
26//! }
27//!
28//! #[derive(PropertiesConfig, Deserialize)]
29//! #[prefix = "server"]
30//! struct ServerConfig {
31//!     port: u16,
32//!     host: String,
33//! }
34//!
35//! let config = Config::load().unwrap();
36//! let server = config.get::<ServerConfig>().unwrap();
37//! ```
38
39#![warn(missing_docs)]
40#![warn(unreachable_pub)]
41// Allow dead_code: This is a framework library with many public APIs that are
42// provided for users but not used internally. This is expected and intentional.
43// 允许 dead_code:这是一个框架库,包含许多公共 API 供用户使用但内部未使用。
44// 这是预期且有意的设计。
45#![allow(dead_code)]
46
47#[cfg(test)]
48mod tests;
49
50mod config;
51mod encrypt;
52mod environment;
53mod error;
54mod loader;
55mod properties;
56mod refresh;
57mod source;
58mod value;
59
60pub use config::{Config, ConfigBuilder, FileFormat, ReloadStrategy};
61pub use encrypt::{ConfigEncryptor, EncryptError};
62pub use environment::{ActiveProfiles, Environment, Profile};
63pub use error::{ConfigError, ConfigResult};
64pub use loader::{ConfigLoader, ConfigLoaderBuilder, Watcher};
65pub use properties::{PropertiesConfig, PropertiesConfigRegistry};
66pub use refresh::{ConfigChangeEvent, ConfigWatcher, RefreshScope, Refreshable};
67pub use source::{PropertySource, PropertySourceBuilder, PropertySourceType};
68pub use value::{Value, ValueExtractor};
69
70/// Re-exports of commonly used types
71/// 常用类型的重新导出
72pub mod prelude {
73    pub use super::{
74        Config, ConfigBuilder, Environment, Profile, PropertiesConfig, PropertySource, Value,
75        ValueExtractor,
76    };
77}
78
79/// Version of the config module
80pub const VERSION: &str = env!("CARGO_PKG_VERSION");