@@ -4,27 +4,27 @@ use serde::{Serialize, de::DeserializeOwned};
44use std:: path:: Path ;
55use toml:: Value as TomlValue ;
66
7- pub struct Args < ' a , Src : Serialize > {
7+ pub struct Cfg < ' a , Src : Serialize > {
88 pub default : & ' a Src ,
99 pub file_path : fn ( & Src ) -> Option < & str > ,
1010 pub env_prefix : & ' a str ,
1111 pub command_line : & ' a Src ,
1212}
1313
14- impl < ' a , Src : Serialize > Args < ' a , Src > {
15- pub fn eval < Cfg : Serialize + DeserializeOwned > (
14+ impl < ' a , Src : Serialize > Cfg < ' a , Src > {
15+ pub fn eval < Dst : Serialize + DeserializeOwned > (
1616 & self ,
17- ) -> Result < Cfg , ConfigError > {
18- new ( self )
17+ ) -> Result < Dst , ConfigError > {
18+ eval ( self )
1919 }
2020}
2121
22- pub fn new < Src , Cfg > (
23- args : & Args < Src > ,
24- ) -> Result < Cfg , ConfigError >
22+ pub fn eval < Src , Dst > (
23+ cfg : & Cfg < Src > ,
24+ ) -> Result < Dst , ConfigError >
2525where
2626 Src : Serialize ,
27- Cfg : Serialize + DeserializeOwned ,
27+ Dst : Serialize + DeserializeOwned ,
2828{
2929 //
3030 // TODO : use functional style with tierator over
@@ -35,11 +35,11 @@ where
3535 let mut builder = Config :: builder ( ) ;
3636
3737 builder =
38- builder. add_source ( term_to_config ( args . default ) ?) ;
38+ builder. add_source ( term_to_config ( cfg . default ) ?) ;
3939
40- let getter = args . file_path ;
40+ let getter = cfg . file_path ;
4141 if let Some ( path) =
42- getter ( args . command_line ) . or ( getter ( args . default ) )
42+ getter ( cfg . command_line ) . or ( getter ( cfg . default ) )
4343 {
4444 let path = Path :: new ( & path) ;
4545 if path. exists ( ) && path. is_file ( ) {
@@ -53,13 +53,13 @@ where
5353
5454 builder = builder. add_source (
5555 Environment :: with_prefix (
56- & args . env_prefix . to_uppercase ( ) ,
56+ & cfg . env_prefix . to_uppercase ( ) ,
5757 )
5858 . separator ( "_" ) ,
5959 ) ;
6060
6161 builder = builder
62- . add_source ( term_to_config ( args . command_line ) ?) ;
62+ . add_source ( term_to_config ( cfg . command_line ) ?) ;
6363
6464 builder. build ( ) ?. try_deserialize ( )
6565}
0 commit comments