Skip to content

Commit e1b5b42

Browse files
authored
docs: document default environment separator (#724)
The first time I stumbled upon this I wasted like 2 hours trying to figure out how to use environment variables. It really was not obvious that a dot would be the default separator. And it is not even easy to figure out when using bash, because it refuses to accept dots! Today I was starting a new project and it is really bothering me that this is not documented, so here is a pr with just some docs. I did not bother creating an issue, because it felt excessive. Hopefully I did not do anything wrong and this will pr be accepted.
2 parents 49ead71 + e2c7792 commit e1b5b42

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/env.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use crate::ConfigError;
1414
/// config Value type. We have to be aware how the config tree is created from the environment
1515
/// dictionary, therefore we are mindful about prefixes for the environment keys, level separators,
1616
/// encoding form (kebab, snake case) etc.
17+
///
18+
/// For prefixes take a look at [`with_prefix`](Environment::with_prefix()).
19+
/// For level separators take a look at [`separator`](Environment::separator()).
1720
#[must_use]
1821
#[derive(Clone, Debug, Default)]
1922
pub struct Environment {
@@ -35,6 +38,9 @@ pub struct Environment {
3538
/// Optional character sequence that separates each key segment in an environment key pattern.
3639
/// Consider a nested configuration such as `redis.password`, a separator of `_` would allow
3740
/// an environment key of `REDIS_PASSWORD` to match.
41+
///
42+
/// If unset, `.` (a dot) is used. In such case `REDIS.PASSWORD` would be the correct key
43+
/// for the example above.
3844
separator: Option<String>,
3945

4046
/// Optional directive to translate collected keys into a form that matches what serializers
@@ -139,6 +145,9 @@ impl Environment {
139145
/// Optional character sequence that separates each key segment in an environment key pattern.
140146
/// Consider a nested configuration such as `redis.password`, a separator of `_` would allow
141147
/// an environment key of `REDIS_PASSWORD` to match.
148+
///
149+
/// If unset, `.` (a dot) is used. In such case `REDIS.PASSWORD` would be the correct key
150+
/// for the example above.
142151
pub fn separator(mut self, s: &str) -> Self {
143152
self.separator = Some(s.into());
144153
self

0 commit comments

Comments
 (0)