diff --git a/tauri-utils/src/config.rs b/tauri-utils/src/config.rs index 6d766ca46..f79383970 100644 --- a/tauri-utils/src/config.rs +++ b/tauri-utils/src/config.rs @@ -448,10 +448,11 @@ mod build { quote! { vec![#(#items),*] } } - /// Create a `HashMap` constructor, mapping keys and values with other `TokenStream`s. + /// Create a map constructor, mapping keys and values with other `TokenStream`s. /// /// This function is pretty generic because the types of keys AND values get transformed. - fn hashmap_lit( + fn map_lit( + map_type: TokenStream, map: Map, map_key: FuncKey, map_value: FuncValue, @@ -475,12 +476,12 @@ mod build { }); quote! {{ - let mut #ident = ::std::collections::HashMap::new(); + let mut #ident = #map_type::new(); #(#items)* #ident }} } else { - quote! { ::std::collections::HashMap::new() } + quote! { #map_type::new() } } } @@ -523,7 +524,7 @@ mod build { quote! { #prefix::Array(vec![#(#items),*]) } } JsonValue::Object(map) => { - let map = hashmap_lit(map, str_lit, json_value_lit); + let map = map_lit(quote! { ::serde_json::Map }, map, str_lit, json_value_lit); quote! { #prefix::Object(#map) } } } @@ -675,7 +676,14 @@ mod build { self .subcommands .as_ref() - .map(|map| hashmap_lit(map, str_lit, identity)) + .map(|map| { + map_lit( + quote! { ::std::collections::HashMap }, + map, + str_lit, + identity, + ) + }) .as_ref(), ); @@ -721,7 +729,12 @@ mod build { impl ToTokens for PluginConfig { fn to_tokens(&self, tokens: &mut TokenStream) { - let config = hashmap_lit(&self.0, str_lit, json_value_lit); + let config = map_lit( + quote! { ::std::collections::HashMap }, + &self.0, + str_lit, + json_value_lit, + ); tokens.append_all(quote! { ::tauri::api::config::PluginConfig(#config) }) } }