#![cfg_attr(feature = "derive", doc = include_str!("../guide/overview.md"))]
#![doc(test(attr(deny(warnings))))]
#![cfg_attr(
not(feature = "derive"),
doc = r#"A minimal, easy-to-use TOML configuration library for Tokio applications.
The `derive` feature is disabled in this build. Store access and manual trait
implementations remain available:
- [`ConfigStore`] is a cloneable handle to one in-memory TOML document. Its clones
share data; in-memory operations are synchronous and only file I/O is async.
- [`ConfigScope`] describes typed configuration and runtime state, shared through
[`SharedScope<T>`]. Loading and saving explicitly copy data to and from a store.
- [`ConfigTable`] converts plain values to and from nested TOML tables.
- [`table_path`] formats diagnostic paths for manual implementations.
- [`Error`] and [`Result`] carry file, TOML and field-conversion errors;
[`IoOperation`] identifies the phase of a file operation that failed.
- [`toml`] and [`Datetime`] re-export the TOML types used by the public API.
The library enables only Tokio's `sync`, `rt` and `fs` features; enable runtime
features such as `macros` and `rt-multi-thread` in your own dependency. Invalid
input handled by the library returns an error rather than panicking, except for
caller-supplied code, file operations polled without a Tokio runtime, and stack
overflows from deeply nested values built in code or parsed with `toml/unbounded`.
See the [0.1.x migration guide](https://docs.rs/conferencier/%5E0.1.0/conferencier/guide/migration/index.html)
and [runtime requirements](https://docs.rs/conferencier/%5E0.1.0/conferencier/guide/concepts/index.html#reading-a-file-before-the-runtime-starts)
and [nesting limits](https://docs.rs/conferencier/%5E0.1.0/conferencier/guide/concepts/index.html#nesting-limits).
Enable the default `derive` feature for `#[derive(ConfigScope)]`,
`#[derive(ConfigTable)]` and the full
[attribute reference](https://docs.rs/conferencier/%5E0.1.0/conferencier/guide/derive/index.html)."#
)]
mod error;
#[cfg(feature = "derive")]
pub mod guide;
mod scope;
mod store;
mod table;
pub mod table_path;
mod value_conversion;
pub use crate::error::{Error, IoOperation, Result};
pub use crate::scope::ConfigScope;
pub use crate::scope::SharedScope;
pub use crate::store::ConfigStore;
pub use crate::table::ConfigTable;
pub use toml;
pub use toml::value::Datetime;
#[cfg(feature = "derive")]
pub use conferencier_derive::{ConfigScope, ConfigTable};
#[doc(hidden)]
pub mod __private {
pub use std::sync::Arc;
pub use tokio::sync::RwLock;
use crate::scope::SharedScope;
pub use crate::table_path::{child_path, element_path, section_path};
pub use crate::value_conversion::{
array, boolean, boolean_vec, datetime, datetime_vec, float, float_vec, integer,
integer_vec, string, string_vec, table, table_element,
};
#[diagnostic::on_unimplemented(
message = "`#[confer(section = ...)]` requires `#[derive(ConfigScope)]` on the same struct",
label = "`section` applies only to a derived ConfigScope"
)]
pub trait DerivedConfigScope {}
pub fn read_section(store: &crate::ConfigStore, section: &str) -> crate::Result<toml::Table> {
store.read_section(section)
}
pub fn deny_unknown_keys(
table_path: &str,
table: &toml::Table,
known: &[&str],
) -> crate::Result<()> {
match table
.keys()
.filter(|key| !known.contains(&key.as_str()))
.min()
{
Some(key) => Err(crate::Error::unknown_key_error(table_path, key.clone())),
None => Ok(()),
}
}
pub fn new_shared_scope<T>(value: T) -> SharedScope<T> {
Arc::new(RwLock::new(value))
}
}