pub struct AppConfig {
pub app: AppSection,
pub database: DatabaseSection,
pub cache: CacheSection,
pub addons: AddonsSection,
pub log: LogSection,
pub server: ServerSection,
}Expand description
顶层应用配置(含 6 个 section)
Fields§
§app: AppSection应用配置段
database: DatabaseSection数据库配置段
cache: CacheSection缓存配置段
addons: AddonsSection插件配置段
log: LogSection日志配置段
server: ServerSection服务器配置段(HTTP 监听地址与端口)
Implementations§
Source§impl AppConfig
impl AppConfig
Sourcepub async fn load_from_dir(
config_dir: impl AsRef<Path>,
) -> Result<AppConfig, ConfigError>
pub async fn load_from_dir( config_dir: impl AsRef<Path>, ) -> Result<AppConfig, ConfigError>
从配置目录加载所有配置文件
目录结构:
config/
├── app.yml
├── database.yml
├── cache.yml
├── addons.yml
├── log.yml
└── server.ymlSourcepub fn apply_env_overrides(&mut self)
pub fn apply_env_overrides(&mut self)
应用环境变量覆盖
支持以下环境变量格式:
SZ_DB_{CONN}_PASSWORD→database.connections.{conn}.passwordSZ_DB_{CONN}_HOSTNAME→database.connections.{conn}.hostnameSZ_DB_{CONN}_HOSTPORT→database.connections.{conn}.hostportSZ_APP__{KEY}→app.{key}(标准格式,未来扩展)
Sourcepub fn default_connection(&self) -> Option<&DatabaseConnection>
pub fn default_connection(&self) -> Option<&DatabaseConnection>
获取默认数据库连接
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AppConfig
impl<'de> Deserialize<'de> for AppConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AppConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AppConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for AppConfig
impl RefUnwindSafe for AppConfig
impl Send for AppConfig
impl Sync for AppConfig
impl Unpin for AppConfig
impl UnsafeUnpin for AppConfig
impl UnwindSafe for AppConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.