@@ -15,6 +15,14 @@ pub use self::format::FileFormat;
15
15
pub use self :: source:: file:: FileSourceFile ;
16
16
pub use self :: source:: string:: FileSourceString ;
17
17
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
+
18
26
/// A configuration source backed up by a file.
19
27
///
20
28
/// It supports optional automatic file format discovery.
@@ -30,14 +38,6 @@ pub struct File<T, F> {
30
38
required : bool ,
31
39
}
32
40
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
-
41
41
impl < F > File < FileSourceString , F >
42
42
where
43
43
F : FileStoredFormat + ' static ,
@@ -67,15 +67,32 @@ where
67
67
impl File < FileSourceFile , FileFormat > {
68
68
/// Given the basename of a file, will attempt to locate a file by setting its
69
69
/// extension to a registered format.
70
- pub fn with_name ( name : & str ) -> Self {
70
+ pub fn with_name ( base_name : & str ) -> Self {
71
71
Self {
72
72
format : None ,
73
73
required : true ,
74
- source : FileSourceFile :: new ( name . into ( ) ) ,
74
+ source : FileSourceFile :: new ( base_name . into ( ) ) ,
75
75
}
76
76
}
77
77
}
78
78
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
+
79
96
impl < ' a > From < & ' a Path > for File < FileSourceFile , FileFormat > {
80
97
fn from ( path : & ' a Path ) -> Self {
81
98
Self {
@@ -96,23 +113,6 @@ impl From<PathBuf> for File<FileSourceFile, FileFormat> {
96
113
}
97
114
}
98
115
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
-
116
116
impl < T , F > Source for File < T , F >
117
117
where
118
118
F : FileStoredFormat + Debug + Clone + Send + Sync + ' static ,
0 commit comments