impl {{ name }} { pub async fn init() -> Result<{{ name }}, &'static str> { let mut key: &str; {% for field in fields %} {% if field.attr_name.is_empty() %} key = "{{ uppersnake((name.clone() + "_" + field.name.as_str()).as_str()) }}"; {% else %} key = "{{ field.attr_name }}"; {% endif %} {% if contains(["usize","i16","i32","i64","u16","u32","u64","f32","f64","String","bool"], field.typ) %} let {{ field.name }}: Option<{{ field.typ }}> = match std::env::var(key) { Ok(val) => match val.parse() { {% if parse_bool(field.attr_ext) %} Ok(v) => Some({{ field.attr_ext_post_with }}(v).await.unwrap()), {% else %} Ok(v) => Some(v), {% endif %} Err(_) => Some("".parse().unwrap()), }, Err(err) => { {% if field.attr_default.is_empty() %} Some(Default::default()) {% else %} Some("{{ field.attr_default }}".parse().unwrap()) {% endif %} } }; {% else %} let {{ field.name }}: Option<{{ field.typ }}> = match {{ field.typ }}::init().await { {% if parse_bool(field.attr_ext) %} Ok(v) => Some({{ field.attr_ext_post_with }}(v).await.unwrap()), {% else %} Ok(v) => Some(v), {% endif %} Err(_) => None, }; {% endif %} {% endfor %} Ok({{ name }} { {% for field in fields %} {% if field.optional %} {{ field.name }}: {{ field.name }}, {% else %} {{ field.name }}: {{ field.name }}.ok_or("Build failed: missing {{ field.name }}")?, {% endif %} {% endfor %} }) } }