@@ -8,17 +8,31 @@ use std::{convert::Infallible, env::VarError, num::ParseIntError, str::FromStr};
88/// returns a list of all environment variables that are required to load the
99/// struct.
1010///
11- /// The macro also generates a `__EnvError ` type that captures errors that can
11+ /// The macro also generates a `____EnvError ` type that captures errors that can
1212/// occur when trying to create an instance of the struct from environment
1313/// variables. This error type is used in the `FromEnv` trait implementation.
1414///
15+ /// ## [`FromEnv`] vs [`FromEnvVar`]
16+ ///
17+ /// While [`FromEnvVar`] deals with loading simple types from the environment,
18+ /// [`FromEnv`] is for loading complex types. It builds a struct from the
19+ /// environment, usually be delegating each field to a [`FromEnvVar`] or
20+ /// [`FromEnv`] implementation.
21+ ///
22+ /// When using the derive macro, the props of the struct must implement
23+ /// [`FromEnv`] or [`FromEnvVar`]. Props that implement [`FromEnv`] contain all
24+ /// the information needed to load the struct from the environment. Props
25+ /// that implement [`FromEnvVar`] need additional information via attributes.
26+ ///
1527/// ## Attributes
1628///
1729/// The macro supports the following attributes:
18- /// - `var = ""`: The name of the environment variable. This is required if the
19- /// prop implements [`FromEnvVar`].
20- /// - `desc = ""`: A description of the environment variable. This is required
21- /// if the prop implements [`FromEnvVar`].
30+ /// - `var = ""`: The name of the environment variable. **This is required if
31+ /// the prop implements [`FromEnvVar`] and forbidden if the prop implements
32+ /// [`FromEnv`].**
33+ /// - `desc = ""`: A description of the environment variable. **This is required
34+ /// if the prop implements [`FromEnvVar`] and forbidden if the prop
35+ /// implements [`FromEnv`].**
2236/// - `optional`: Marks the prop as optional. This is currently only used in the
2337/// generated `fn inventory`, and is informational.
2438/// - `infallible`: Marks the prop as infallible. This means that the prop
@@ -78,10 +92,20 @@ use std::{convert::Infallible, env::VarError, num::ParseIntError, str::FromStr};
7892/// maybe_not_needed: Option<String>,
7993/// }
8094///
81- /// // The `FromEnv` trait is implemented for the struct, and the struct can
95+ /// #[derive(Debug, FromEnv)]
96+ /// pub struct MyBiggerCfg {
97+ /// #[from_env(var = "BIGGGG_CONFIGGGG", desc = "A big config", infallible)]
98+ /// pub big_config: String,
99+ ///
100+ /// // Note that becuase `MyCfg` implements `FromEnv`, we do not need to
101+ /// // specify the `var` and `desc` attributes.
102+ /// pub little_config: MyCfg,
103+ /// }
104+ ///
105+ /// // The [`FromEnv`] trait is implemented for the struct, and the struct can
82106/// // be loaded from the environment.
83107/// # fn use_it() {
84- /// if let Err(missing) = MyCfg ::check_inventory() {
108+ /// if let Err(missing) = MyBiggerCfg ::check_inventory() {
85109/// println!("Missing environment variables:");
86110/// for var in missing {
87111/// println!("{}: {}", var.var, var.description);
@@ -90,7 +114,7 @@ use std::{convert::Infallible, env::VarError, num::ParseIntError, str::FromStr};
90114/// # }
91115/// ```
92116///
93- /// This will generate a `FromEnv` implementation for the struct, and a
117+ /// This will generate a [ `FromEnv`] implementation for the struct, and a
94118/// `MyCfgEnvError` type that is used to represent errors that can occur when
95119/// loading from the environment. The error generated will look like this:
96120///
@@ -104,6 +128,8 @@ use std::{convert::Infallible, env::VarError, num::ParseIntError, str::FromStr};
104128///
105129/// [`Infallible`]: std::convert::Infallible
106130/// [`SlotCalculator`]: crate::utils::SlotCalculator
131+ /// [`FromEnv`]: crate::utils::from_env::FromEnv
132+ /// [`FromEnvVar`]: crate::utils::from_env::FromEnvVar
107133pub use init4_from_env_derive:: FromEnv ;
108134
109135/// Details about an environment variable. This is used to generate
0 commit comments