conf/lib.rs
1//! A `derive`-based, highly composable env-and-argument parser aimed at the practically-minded web
2//! developer building large web projects.
3//!
4//! To use `conf`, use the `#[derive(Conf)]` proc macro on your configuration struct.
5//! Then call a [`Conf`] trait function to parse your configuration struct.
6//! Proc macro attributes are documented there.
7//!
8//! See README for an overview.
9#![deny(unsafe_code)]
10#![deny(missing_docs)]
11
12mod builder;
13mod conf_context;
14mod error;
15mod find_parameter;
16mod parse_env;
17mod parser;
18mod program_option;
19mod str_to_bool;
20mod traits;
21
22// These are not needed by users or by generated code
23use conf_context::FlattenedOptionalDebugInfo;
24use parse_env::parse_env;
25use parser::ParsedArgs;
26use str_to_bool::str_to_bool;
27
28// These exports represent the public API.
29pub use builder::ConfBuilder;
30pub use error::Error;
31pub use find_parameter::find_parameter;
32pub use traits::{Conf, Subcommands};
33// Export conf_derive proc-macros unconditionally. Their docs are on the traits that they
34// produce implementations for.
35#[doc(hidden)]
36pub use conf_derive::{self, *};
37
38// The derive macro needs these other types, so they are exported, but doc(hidden).
39#[doc(hidden)]
40pub use conf_context::{ConfContext, ConfValueSource};
41#[doc(hidden)]
42pub use error::InnerError;
43#[doc(hidden)]
44pub use parse_env::ParsedEnv;
45#[doc(hidden)]
46pub use parser::{Parser, ParserConfig};
47#[doc(hidden)]
48pub use program_option::{ParseType, ProgramOption};
49
50// The serde feature brings in some more types and traits
51#[cfg(feature = "serde")]
52mod conf_serde;
53// These are publicly documented. Everything needed to understand how to use the builder
54// should be well-documented.
55#[cfg(feature = "serde")]
56pub use conf_serde::{ConfSerde, ConfSerdeBuilder};
57// These are internals used by the derive macro.
58#[doc(hidden)]
59#[cfg(feature = "serde")]
60pub use conf_serde::{ConfSerdeContext, IdentString, NextValueProducer, SubcommandsSerde};
61// Re-export serde crate for the proc macro
62#[doc(hidden)]
63#[cfg(feature = "serde")]
64pub use serde::{self, *};
65
66// CowStr is used internally mainly because using it allows us to construct ProgramOption in a const
67// way from string literals, but also to modify them if they have to be flattened into something.
68type CowStr = std::borrow::Cow<'static, str>;
69
70// Helper for some of the proc-macro code-gen
71// This lets you get the inner-type of a Vec<T> no matter how Vec<T> is spelled
72// (Vec, std::vec::Vec, alloc::vec::Vec) or aliased by user code.
73// This is normally difficult to do directly from a proc-macro, which can only see the tokens.
74#[doc(hidden)]
75pub trait InnerTypeHelper {
76 type Ty;
77}
78
79impl<T> InnerTypeHelper for Vec<T> {
80 type Ty = T;
81}