File tree Expand file tree Collapse file tree 1 file changed +12
-30
lines changed
Expand file tree Collapse file tree 1 file changed +12
-30
lines changed Original file line number Diff line number Diff line change @@ -41,36 +41,18 @@ impl Config{
4141 }
4242 }
4343 pub fn init ( ) ->Self {
44- let builder=config:: Config :: builder ( ) ;
45- let builder=match builder. set_default ( "exceptions" , Vec :: < u16 > :: new ( ) ) {
46- Ok ( b) =>b,
47- Err ( e) =>{
48- log:: error!( "Failed to set default config: {}" , e) ;
49- return Self :: new ( ) ;
50- }
51- } ;
52- let builder=match builder. set_default ( "debounce_time" , 14 ) {
53- Ok ( b) =>b,
54- Err ( e) =>{
55- log:: error!( "Failed to set default config: {}" , e) ;
56- return Self :: new ( ) ;
57- }
58- } ;
59- let builder=builder. add_source ( config:: File :: with_name ( "/etc/debouncer.toml" ) ) ;
60- let config=match builder. build ( ) {
61- Ok ( c) =>c,
62- Err ( e) =>{
63- log:: warn!( "Failed to build config: {}" , e) ;
64- return Self :: new ( ) ;
65- }
66- } ;
67- match config. try_deserialize :: < Config > ( ) {
68- Ok ( c) =>c,
69- Err ( e) =>{
70- log:: error!( "Failed to parse config file: {}" , e) ;
71- return Self :: new ( ) ;
72- }
73- }
44+ Self :: init_impl ( ) . unwrap_or_else ( |e|{
45+ log:: error!( "Failed to init Config: {}" , e) ;
46+ Self :: new ( )
47+ } )
48+ }
49+ fn init_impl ( ) ->Result < Self , config:: ConfigError > {
50+ let config=config:: Config :: builder ( )
51+ . set_default ( "exceptions" , Vec :: < u16 > :: new ( ) ) ?
52+ . set_default ( "debounce_time" , 14 ) ?
53+ . add_source ( config:: File :: with_name ( "/etc/debouncer.toml" ) )
54+ . build ( ) ?;
55+ config. try_deserialize :: < Config > ( )
7456 }
7557}
7658pub static CONFIG : std:: sync:: OnceLock < Config > =std:: sync:: OnceLock :: new ( ) ;
You can’t perform that action at this time.
0 commit comments