Skip to main content

MultiSourceConfig

Struct MultiSourceConfig 

Source
pub struct MultiSourceConfig { /* private fields */ }
Expand description

多源配置合并器:从文件、环境变量、远程配置中心收集配置并按优先级合并

Implementations§

Source§

impl MultiSourceConfig

Source

pub fn new() -> Self

Source

pub fn set_file_config(&mut self, config: HashMap<String, String>)

设置文件来源配置

Source

pub fn set_env_config(&mut self, config: HashMap<String, String>)

设置环境变量来源配置

Source

pub fn set_remote_config(&mut self, config: HashMap<String, String>)

设置远程配置中心来源配置

Source

pub fn load_env_vars(&mut self, prefix: &str)

从系统环境变量加载配置(前缀过滤)

Source

pub fn load_json(&mut self, json: &str) -> Result<(), String>

从 JSON 文件内容加载配置

Source

pub fn merge(&self) -> HashMap<String, String>

合并所有来源并返回结果(高优先级覆盖低优先级)

Source

pub fn get(&self, key: &str) -> Option<String>

获取合并后的配置值

Source

pub fn source_of(&self, key: &str) -> Option<ConfigSourcePriority>

返回某个 key 的来源优先级

Trait Implementations§

Source§

impl Default for MultiSourceConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.