pub struct ConfigBuilder { /* private fields */ }Expand description
分层配置构建器,支持文件 → 环境变量 → 程序化覆盖。
use cc_core::ConfigBuilder;
let cfg = ConfigBuilder::new()
.with_mysql("default", |m| m.host("127.0.0.1").user("root").password("pw").database("mydb"))
.with_redis("cache", |r| r.url("redis://localhost:6379"))
.build()
.unwrap();Implementations§
Source§impl ConfigBuilder
impl ConfigBuilder
pub fn new() -> Self
Sourcepub fn env_prefix(self, prefix: impl Into<String>) -> Self
pub fn env_prefix(self, prefix: impl Into<String>) -> Self
设置环境变量前缀(默认 “CC”)。
Sourcepub fn with_env(self) -> Result<Self>
pub fn with_env(self) -> Result<Self>
读取环境变量覆盖。格式:<PREFIX>_MYSQL_<NAME>_<FIELD> / <PREFIX>_REDIS_<NAME>_<FIELD>
Sourcepub fn with_mysql(
self,
name: impl Into<String>,
f: impl FnOnce(MysqlConfigBuilder) -> MysqlConfigBuilder,
) -> Self
pub fn with_mysql( self, name: impl Into<String>, f: impl FnOnce(MysqlConfigBuilder) -> MysqlConfigBuilder, ) -> Self
程序化添加 / 覆盖单个 MySQL 连接。
Sourcepub fn with_redis(
self,
name: impl Into<String>,
f: impl FnOnce(RedisConfigBuilder) -> RedisConfigBuilder,
) -> Self
pub fn with_redis( self, name: impl Into<String>, f: impl FnOnce(RedisConfigBuilder) -> RedisConfigBuilder, ) -> Self
程序化添加 / 覆盖单个 Redis 连接。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConfigBuilder
impl RefUnwindSafe for ConfigBuilder
impl Send for ConfigBuilder
impl Sync for ConfigBuilder
impl Unpin for ConfigBuilder
impl UnsafeUnpin for ConfigBuilder
impl UnwindSafe for ConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more