#![doc = include_str!("../README.md")]
#![cfg_attr(dynconfig_nightly, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![no_std]
extern crate alloc;
extern crate self as dynconfig;
#[cfg(feature = "std")]
extern crate std;
mod error;
mod path;
mod value;
pub mod pair;
pub use self::error::Error;
pub use self::path::Path;
pub use self::value::Value;
#[allow(missing_docs)]
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[cfg(feature = "derive")]
#[doc(inline)]
pub use dynconfig_derive::Dynconfig;
pub trait Dynconfig: Sized {
fn set(&mut self, path: &mut Path<'_>, value: &str) -> Result<()>;
}
impl<T> Dynconfig for T
where
T: Value,
{
fn set(&mut self, _: &mut Path<'_>, value: &str) -> Result<()> {
Value::update(self, value)
}
}
#[doc(inline)]
pub use self::pair::Pair;
#[doc(inline)]
pub use self::pair::parse;
#[inline]
pub fn set<T>(x: &mut T, pair: Pair<'_>) -> Result<()>
where
T: Dynconfig,
{
pair.set_on(x)
}
pub fn set_many<'a, T, I>(x: &mut T, iter: I) -> Result<()>
where
T: Dynconfig,
I: IntoIterator<Item = Pair<'a>>,
{
iter.into_iter().try_for_each(|pair| set(x, pair))
}