From 868a3415a6c6bcf290a19bd8fa19f2d9601bf6ce Mon Sep 17 00:00:00 2001 From: GnomedDev Date: Wed, 13 Nov 2024 21:20:28 +0000 Subject: [PATCH] deploy: 3a2ab5ec1dd0e0ab26cdba148a33f53480da8d36 --- next/src/poise_macros/command/slash.rs.html | 48 +++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/next/src/poise_macros/command/slash.rs.html b/next/src/poise_macros/command/slash.rs.html index 07b0951480f..65fb3a78dde 100644 --- a/next/src/poise_macros/command/slash.rs.html +++ b/next/src/poise_macros/command/slash.rs.html @@ -220,13 +220,49 @@ 219 220 221 -222
use super::Invocation;
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
use super::Invocation;
 use crate::util::{
     extract_type_parameter, iter_tuple_2_to_hash_map, tuple_2_iter_deref, wrap_option_to_string,
+    List,
 };
 use quote::format_ident;
 use syn::spanned::Spanned as _;
 
+fn lit_to_string(lit: &syn::Lit) -> Result<String, syn::Error> {
+    match lit {
+        syn::Lit::Str(lit_str) => Ok(lit_str.value()),
+        syn::Lit::Char(lit_char) => Ok(lit_char.value().to_string()),
+        syn::Lit::Int(lit_int) => Ok(lit_int.base10_digits().to_owned()),
+        syn::Lit::Float(lit_float) => Ok(lit_float.token().to_string()),
+        syn::Lit::Bool(lit_bool) => Ok(lit_bool.value.to_string()),
+
+        _ => Err(syn::Error::new(
+            lit.span(),
+            "Inline choice must be convertable to a string at compile time",
+        )),
+    }
+}
+
 pub fn generate_parameters(inv: &Invocation) -> Result<Vec<proc_macro2::TokenStream>, syn::Error> {
     let mut parameter_structs = Vec::new();
     for param in &inv.parameters {
@@ -299,10 +335,14 @@
         // TODO: move this to poise::CommandParameter::choices (is there a reason not to?)
         let choices = match inv.args.slash_command {
             true => {
-                if let Some(choices) = &param.args.choices {
-                    let choices = &choices.0;
+                if let Some(List(choices)) = &param.args.choices {
+                    let choices = choices
+                        .iter()
+                        .map(lit_to_string)
+                        .collect::<Result<Vec<_>, _>>()?;
+
                     quote::quote! { vec![#( ::poise::CommandParameterChoice {
-                        name: ToString::to_string(&#choices),
+                        name: String::from(#choices),
                         localizations: Default::default(),
                         __non_exhaustive: (),
                     } ),*] }