Repository: starship/starship
File: starship_module_config_derive/src/lib.rs (Rust)

Code before:
                    #load_tokens
                    #new_load_tokens
                };

                fields = quote! {
                    #fields
                    #new_field
                };
            }

            load_config = quote! {
                fn load_config(&mut self, config: &'a toml::Value) {
                    if let toml::Value::Table(config) = config {
                        config.iter().for_each(|(k, v)| {
                            match k.as_str() {
                                #load_tokens
                                unknown => {
                                    ::log::warn!("Unknown config key '{}'", unknown);

                                    let did_you_mean = ::std::array::IntoIter::new([#fields])
                                    .filter_map(|field| {
                                        let score = ::strsim::jaro_winkler(unknown, field);
                                        (score > 0.8).then(|| (score, field))
                                    })
                                    .max_by(
                                        |(score_a, _field_a), (score_b, _field_d)| {
                                            score_a.partial_cmp(score_b).unwrap_or(::std::cmp::Ordering::Equal)
                                        },
                                    );

                                    if let Some((_score, field)) = did_you_mean {
                                        ::log::warn!("Did you mean '{}'?", field);
                                    }
                                },
                            }
                        });
                    }
                }
            };
            from_config = quote! {
                fn from_config(config: &'a toml::Value) -> Option<Self> {
                    let mut out = Self::default();
                    out.load_config(config);
                    Some(out)
                }
            };
        }
    }

    TokenStream::from(quote! {
        impl<'a> ModuleConfig<'a> for #struct_ident #ty_generics #where_clause {

Review comment (suggestion):
Also here

```suggestion
                                        |(score_a, _field_a), (score_b, _field_b)| {
```


Code after:
                    #load_tokens
                    #new_load_tokens
                };

                fields = quote! {
                    #fields
                    #new_field
                };
            }

            load_config = quote! {
                fn load_config(&mut self, config: &'a toml::Value) {
                    if let toml::Value::Table(config) = config {
                        config.iter().for_each(|(k, v)| {
                            match k.as_str() {
                                #load_tokens
                                unknown => {
                                    ::log::warn!("Unknown config key '{}'", unknown);

                                    let did_you_mean = ::std::array::IntoIter::new([#fields])
                                    .filter_map(|field| {
                                        let score = ::strsim::jaro_winkler(unknown, field);
                                        (score > 0.8).then(|| (score, field))
                                    })
                                    .max_by(
                                        |(score_a, _field_a), (score_b, _field_b)| {
                                            score_a.partial_cmp(score_b).unwrap_or(::std::cmp::Ordering::Equal)
                                        },
                                    );

                                    if let Some((_score, field)) = did_you_mean {
                                        ::log::warn!("Did you mean '{}'?", field);
                                    }
                                },
                            }
                        });
                    }
                }
            };
            from_config = quote! {
                fn from_config(config: &'a toml::Value) -> Option<Self> {
                    let mut out = Self::default();
                    out.load_config(config);
                    Some(out)
                }
            };
        }
    }

    TokenStream::from(quote! {
        impl<'a> ModuleConfig<'a> for #struct_ident #ty_generics #where_clause {