Skip to content

Commit 16c1072

Browse files
authored
Merge pull request #647 from epage/docs
docs: Clean up
2 parents 508ee7c + 810d629 commit 16c1072

File tree

9 files changed

+60
-56
lines changed

9 files changed

+60
-56
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ values back to the configuration file(s)!
2828

2929
## Usage
3030

31-
```toml
32-
[dependencies]
33-
config = "0.14.0"
34-
```
35-
3631
### Feature flags
3732

3833
- `ini` - Adds support for reading INI files

src/builder.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ enum SourceType {
125125
impl BuilderState for DefaultState {}
126126
impl BuilderState for AsyncState {}
127127

128+
/// Operations allowed in any state
128129
impl<St: BuilderState> ConfigBuilder<St> {
129-
// operations allowed in any state
130-
131130
/// Set a default `value` at `key`
132131
///
133132
/// This value can be overwritten by any [`Source`], [`AsyncSource`] or override.
@@ -183,9 +182,8 @@ impl<St: BuilderState> ConfigBuilder<St> {
183182
}
184183
}
185184

185+
/// Operations allowed in sync state
186186
impl ConfigBuilder<DefaultState> {
187-
// operations allowed in sync state
188-
189187
/// Registers new [`Source`] in this builder.
190188
///
191189
/// Calling this method does not invoke any I/O. [`Source`] is only saved in internal register for later use.
@@ -273,9 +271,8 @@ impl ConfigBuilder<DefaultState> {
273271
}
274272
}
275273

274+
/// Operations allowed in async state
276275
impl ConfigBuilder<AsyncState> {
277-
// operations allowed in async state
278-
279276
/// Registers new [`Source`] in this builder.
280277
///
281278
/// Calling this method does not invoke any I/O. [`Source`] is only saved in internal register for later use.

src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use crate::ser::ConfigSerializer;
1111
use crate::source::Source;
1212
use crate::value::{Table, Value};
1313

14-
/// A prioritized configuration repository. It maintains a set of
15-
/// configuration sources, fetches values to populate those, and provides
14+
/// A prioritized configuration repository.
15+
///
16+
/// It maintains a set of configuration sources, fetches values to populate those, and provides
1617
/// them according to the source's priority.
1718
#[derive(Clone, Debug)]
1819
pub struct Config {

src/file/mod.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ pub use self::format::FileFormat;
1515
pub use self::source::file::FileSourceFile;
1616
pub use self::source::string::FileSourceString;
1717

18+
/// An extension of [`Format`] trait.
19+
///
20+
/// Associates format with file extensions, therefore linking storage-agnostic notion of format to a file system.
21+
pub trait FileStoredFormat: Format {
22+
/// Returns a vector of file extensions, for instance `[yml, yaml]`.
23+
fn file_extensions(&self) -> &'static [&'static str];
24+
}
25+
1826
/// A configuration source backed up by a file.
1927
///
2028
/// It supports optional automatic file format discovery.
@@ -30,14 +38,6 @@ pub struct File<T, F> {
3038
required: bool,
3139
}
3240

33-
/// An extension of [`Format`] trait.
34-
///
35-
/// Associates format with file extensions, therefore linking storage-agnostic notion of format to a file system.
36-
pub trait FileStoredFormat: Format {
37-
/// Returns a vector of file extensions, for instance `[yml, yaml]`.
38-
fn file_extensions(&self) -> &'static [&'static str];
39-
}
40-
4141
impl<F> File<FileSourceString, F>
4242
where
4343
F: FileStoredFormat + 'static,
@@ -67,15 +67,32 @@ where
6767
impl File<FileSourceFile, FileFormat> {
6868
/// Given the basename of a file, will attempt to locate a file by setting its
6969
/// extension to a registered format.
70-
pub fn with_name(name: &str) -> Self {
70+
pub fn with_name(base_name: &str) -> Self {
7171
Self {
7272
format: None,
7373
required: true,
74-
source: FileSourceFile::new(name.into()),
74+
source: FileSourceFile::new(base_name.into()),
7575
}
7676
}
7777
}
7878

79+
impl<T, F> File<T, F>
80+
where
81+
F: FileStoredFormat + 'static,
82+
T: FileSource<F>,
83+
{
84+
pub fn format(mut self, format: F) -> Self {
85+
self.format = Some(format);
86+
self
87+
}
88+
89+
/// Set required to false to make a file optional when building the config.
90+
pub fn required(mut self, required: bool) -> Self {
91+
self.required = required;
92+
self
93+
}
94+
}
95+
7996
impl<'a> From<&'a Path> for File<FileSourceFile, FileFormat> {
8097
fn from(path: &'a Path) -> Self {
8198
Self {
@@ -96,23 +113,6 @@ impl From<PathBuf> for File<FileSourceFile, FileFormat> {
96113
}
97114
}
98115

99-
impl<T, F> File<T, F>
100-
where
101-
F: FileStoredFormat + 'static,
102-
T: FileSource<F>,
103-
{
104-
pub fn format(mut self, format: F) -> Self {
105-
self.format = Some(format);
106-
self
107-
}
108-
109-
/// Set required to false to make a file optional when building the config.
110-
pub fn required(mut self, required: bool) -> Self {
111-
self.required = required;
112-
self
113-
}
114-
}
115-
116116
impl<T, F> Source for File<T, F>
117117
where
118118
F: FileStoredFormat + Debug + Clone + Send + Sync + 'static,

src/file/source/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt::Debug;
66

77
use crate::{file::FileStoredFormat, Format};
88

9-
/// Describes where the file is sourced
9+
/// Describes where the [`File`][super::File] is sourced
1010
pub trait FileSource<T>: Debug + Clone
1111
where
1212
T: Format + FileStoredFormat,

src/lib.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
//! Config organizes hierarchical or layered configurations for Rust applications.
1+
//! [`Config`] organizes hierarchical or layered configurations for Rust applications.
22
//!
3-
//! Config lets you set a set of default parameters and then extend them via merging in
3+
//! [`Config`] lets you set a set of [default parameters][ConfigBuilder::set_default] and then extend them via merging in
44
//! configuration from a variety of sources:
55
//!
6-
//! - Environment variables
7-
//! - String literals in well-known formats
8-
//! - Another Config instance
9-
//! - Files: TOML, JSON, YAML, INI, RON, JSON5 and custom ones defined with Format trait
10-
//! - Manual, programmatic override (via a `.set` method on the Config instance)
6+
//! - [Environment variables][Environment]
7+
//! - [String literals][FileSourceString] in [well-known formats][FileFormat]
8+
//! - Another [`Config`] instance
9+
//! - [Files][FileSourceFile] in [well known formats][FileFormat] and custom ones defined with [`Format`] trait
10+
//! - Manual, programmatic [overrides][ConfigBuilder::set_override]
1111
//!
12-
//! Additionally, Config supports:
12+
//! Additionally, [`Config`] supports:
1313
//!
1414
//! - Live watching and re-reading of configuration files
1515
//! - Deep access into the merged configuration via a path syntax
1616
//! - Deserialization via `serde` of the configuration or any subset defined via a path
1717
//!
18-
//! See the [examples](https://github.com/mehcode/config-rs/tree/master/examples) for
18+
//! # Example
19+
//!
20+
//! ```rust
21+
//! # #[cfg(feature = "toml")] {
22+
#![doc = include_str!("../examples/simple/main.rs")]
23+
//! # }
24+
//! ```
25+
//!
26+
//! See more [examples](https://github.com/mehcode/config-rs/tree/master/examples) for
1927
//! general usage information.
2028
2129
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

src/map.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
/// The backing store for [`Config`][crate::Config]
2+
pub type Map<K, V> = InternalMap<K, V>;
3+
14
#[cfg(not(feature = "preserve_order"))]
2-
pub type Map<K, V> = std::collections::HashMap<K, V>;
5+
type InternalMap<K, V> = std::collections::HashMap<K, V>;
36
#[cfg(feature = "preserve_order")]
4-
pub type Map<K, V> = indexmap::IndexMap<K, V>;
7+
type InternalMap<K, V> = indexmap::IndexMap<K, V>;

src/source.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::value::{Value, ValueKind};
1313
pub trait Source: Debug {
1414
fn clone_into_box(&self) -> Box<dyn Source + Send + Sync>;
1515

16-
/// Collect all configuration properties available from this source and return
17-
/// a Map.
16+
/// Collect all configuration properties available from this source into
17+
/// a [`Map`].
1818
fn collect(&self) -> Result<Map<String, Value>>;
1919

2020
/// Collects all configuration properties to a provided cache.

src/value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::map::Map;
99

1010
/// Underlying kind of the configuration value.
1111
///
12-
/// Standard operations on a `Value` by users of this crate do not require
13-
/// knowledge of `ValueKind`. Introspection of underlying kind is only required
12+
/// Standard operations on a [`Value`] by users of this crate do not require
13+
/// knowledge of [`ValueKind`]. Introspection of underlying kind is only required
1414
/// when the configuration values are unstructured or do not have known types.
1515
#[derive(Debug, Clone, PartialEq)]
1616
pub enum ValueKind {

0 commit comments

Comments
 (0)