miau/
lib.rs

1//! # Miau
2//!
3//! ## What
4//! **Async aware and extensible layered configuration system for Rust**
5//! `Miau` allows you to gather configuration from many sources, including, but not limited to:
6//! * files
7//! * environment
8//! * in memory
9//!
10//! It is built around `Serde` that does heavy lifitng part of transforming data formats into other ones. It is battle tested and perfromant.
11//! `Miau` utilizes its capabilities to the fullest!
12//!
13//! `Miau`'s data model allows to layer configuration trees in order of choice and convert them into Rust structs
14//! or use as-is retrieving configuration values directy from trees on the go.
15//! Furthermore, it allows scoping into configuration sections using dead simple DSL keeping the same capabilities.
16//!
17//! It is built with async and extensibility in mind. Thanks to `async_trait` crate it is possible to define asynchronous configuration sources.
18//!
19//! ## How
20//!
21//! Building configuration is simple. Library defines two builders (for blocking and non-blocking sources also known as synchronous and asynchronous)
22//! that accept sources and formats. It is lazy - no data will be fetched until builder is built.
23//!
24//! A simple example underneath.
25//!```rust
26//!use miau::{
27//!    builder::ConfigurationBuilder, configuration::ConfigurationRead, format, format::Json5,
28//!    provider::EnvironmentProvider, source::{FileSource, InMemorySource},
29//!};
30//!use std::collections::HashMap;
31//!use std::env;
32//!
33//!fn main() {
34//!    let mut some_collection: HashMap<String, String> = HashMap::new();
35//!    some_collection.insert("key".into(), "value".into());
36//!
37//!    let mut builder = ConfigurationBuilder::default();
38//!
39//!    let result = builder
40//!        .add_provider(EnvironmentProvider::with_prefix("ASDFA"))
41//!        .add(
42//!            InMemorySource::from_string_slice(r#"{"key" : "value"}"#),
43//!            format::json())
44//!        .add_provider(some_collection)
45//!        .build();
46//!
47//!    let configuration = match result {
48//!        Ok(configuration) => configuration,
49//!        Err(e) => panic!(
50//!            "You should handle it more gracefull in your app! {}",
51//!            e.pretty_display()
52//!        ),
53//!    };
54//!
55//!    // `get` method is defined in ConfigurationRead trait. It has to be in scope!
56//!    let from_map_then_array: Option<i32> = configuration.get("map:[1]");
57//!}
58//!```
59//!
60//! **Refer to examples inside the source code repository to learn how to construct configuration and define your own sources.**
61//!
62//!## Why
63//!
64//!While writing his own applications in Rust author of this library noticed that existing libraries to create layered configuration are either unmaintained, lack support for `async` or are in other ways not extensible enough.
65//!
66//!Goal of this library is to provide core functionality of creating layered configuration that is not likely to change often and can be extended via traits. It is not meant for `Miau` to become heavy or polutted with optional dependencies needed for specialized use cases.
67//!
68//!That is why its only heavy dependency is `serde` and it only defines `Sources` and `Providers` that can be implemented using standard library. Only most popular formats are part of `Miau` and even they are all feature flagged. This is also why no `async` trait is implemented - there are multiple heavy executors. For the same reason no HTTP source is included - HTTP libraries are numerous.
69//!
70//!Implementing support for aforementioned utilities should be done in separate crates (which is possible thanks to public traits).
71//!
72//!## Feature flags
73//!
74//!By default no feature flag is enabled.
75//!
76//!* `ini` - activates support for Ini format
77//!* `json` - activates support for Json format
78//!* `msgpack` - activates support for Message Pack format
79//!* `serde_json5` - activates support for Json5 format
80//!* `serde_toml` - activates support for Toml format
81//!* `yaml` - activates support for Yaml format
82//!* `all` - activates all other feature flags
83
84#![deny(unsafe_code)]
85#![deny(missing_docs)]
86/// Configuration builders
87pub mod builder;
88/// Actual configuration
89#[macro_use]
90pub mod configuration;
91mod de;
92/// All configuration errors
93pub mod error;
94/// Configuration formats
95pub mod format;
96mod parsing;
97/// Configuration providers
98pub mod provider;
99/// Configuration sources
100pub mod source;