File tree Expand file tree Collapse file tree 4 files changed +11
-7
lines changed Expand file tree Collapse file tree 4 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " dotenv_config"
3- version = " 0.2.0 "
3+ version = " 0.2.1 "
44edition = " 2021"
55authors = [
" Hengfei Yang <[email protected] >" ]
66description = " parse `env` to config struct for Rust"
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ struct Redis {
2424
2525fn main ( ) {
2626 dotenv ( ) . ok ( ) ;
27- let cfg = Config :: init ( ) . unwrap ( ) ;
27+ let cfg = Config :: init ( ) . expect ( "config init error" ) ;
2828 println ! ( "{:#?}" , cfg) ;
2929 assert ! ( cfg. server_addr == "192.168.2.1" ) ;
3030 assert ! ( !cfg. server_mode) ;
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ mod builder;
8080pub fn derive_env_config ( input : TokenStream ) -> TokenStream {
8181 // println!("{:#?}", input);
8282 builder:: BuilderContext :: render ( input)
83- . unwrap ( )
83+ . expect ( "render error" )
8484 . parse ( )
85- . unwrap ( )
85+ . expect ( "parse error" )
8686}
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ impl {{ name }} {
2525 help_map
2626 }
2727
28- pub fn init() -> Result<{{ name }}, String > {
28+ pub fn init() -> Result<{{ name }}, & 'static str > {
2929 let mut key: &str ;
3030 {% for field in fields %}
3131 {% if field .attr_name .is_empty () %}
@@ -37,7 +37,9 @@ impl {{ name }} {
3737 let {{ field.name }}: Option<{{ field.typ }}> = match std::env::var(key) {
3838 Ok(val) => match val.to_lowercase().parse() {
3939 Ok(v) => Some(v),
40- Err(_) => {return Err(format!("{}: except a value of [{{ field.typ }}]", key));},
40+ Err(_) => {
41+ panic!("EnvConfig: {} except a value of [{{ field.typ }}]", key);
42+ },
4143 },
4244 Err(err) => {
4345 {% if field .attr_default .is_empty () %}
@@ -62,7 +64,9 @@ impl {{ name }} {
6264 let {{ field.name }}: Option<{{ field.typ }}> = match std::env::var(key) {
6365 Ok(val) => match val.parse::<{{ field.typ }}>() {
6466 Ok(v) => Some(v),
65- Err(_) => {return Err(format!("{}: except a value of [{{ field.typ }}]", key));},
67+ Err(_) => {
68+ panic!("EnvConfig: {} except a value of [{{ field.typ }}]", key);
69+ },
6670 },
6771 Err(_) => {
6872 {% if field .attr_default .is_empty () %}
You can’t perform that action at this time.
0 commit comments