Skip to content

Commit

Permalink
deploy: 3a2ab5e
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Nov 13, 2024
1 parent e3b6357 commit 868a341
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions next/src/poise_macros/command/slash.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,49 @@
<a href="#219" id="219">219</a>
<a href="#220" id="220">220</a>
<a href="#221" id="221">221</a>
<a href="#222" id="222">222</a></pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::Invocation;
<a href="#222" id="222">222</a>
<a href="#223" id="223">223</a>
<a href="#224" id="224">224</a>
<a href="#225" id="225">225</a>
<a href="#226" id="226">226</a>
<a href="#227" id="227">227</a>
<a href="#228" id="228">228</a>
<a href="#229" id="229">229</a>
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a></pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">super</span>::Invocation;
<span class="kw">use </span><span class="kw">crate</span>::util::{
extract_type_parameter, iter_tuple_2_to_hash_map, tuple_2_iter_deref, wrap_option_to_string,
List,
};
<span class="kw">use </span>quote::format_ident;
<span class="kw">use </span>syn::spanned::Spanned <span class="kw">as _</span>;

<span class="kw">fn </span>lit_to_string(lit: <span class="kw-2">&amp;</span>syn::Lit) -&gt; <span class="prelude-ty">Result</span>&lt;String, syn::Error&gt; {
<span class="kw">match </span>lit {
syn::Lit::Str(lit_str) =&gt; <span class="prelude-val">Ok</span>(lit_str.value()),
syn::Lit::Char(lit_char) =&gt; <span class="prelude-val">Ok</span>(lit_char.value().to_string()),
syn::Lit::Int(lit_int) =&gt; <span class="prelude-val">Ok</span>(lit_int.base10_digits().to_owned()),
syn::Lit::Float(lit_float) =&gt; <span class="prelude-val">Ok</span>(lit_float.token().to_string()),
syn::Lit::Bool(lit_bool) =&gt; <span class="prelude-val">Ok</span>(lit_bool.value.to_string()),

<span class="kw">_ </span>=&gt; <span class="prelude-val">Err</span>(syn::Error::new(
lit.span(),
<span class="string">"Inline choice must be convertable to a string at compile time"</span>,
)),
}
}

<span class="kw">pub fn </span>generate_parameters(inv: <span class="kw-2">&amp;</span>Invocation) -&gt; <span class="prelude-ty">Result</span>&lt;Vec&lt;proc_macro2::TokenStream&gt;, syn::Error&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>parameter_structs = Vec::new();
<span class="kw">for </span>param <span class="kw">in </span><span class="kw-2">&amp;</span>inv.parameters {
Expand Down Expand Up @@ -299,10 +335,14 @@
// TODO: move this to poise::CommandParameter::choices (is there a reason not to?)
</span><span class="kw">let </span>choices = <span class="kw">match </span>inv.args.slash_command {
<span class="bool-val">true </span>=&gt; {
<span class="kw">if let </span><span class="prelude-val">Some</span>(choices) = <span class="kw-2">&amp;</span>param.args.choices {
<span class="kw">let </span>choices = <span class="kw-2">&amp;</span>choices.<span class="number">0</span>;
<span class="kw">if let </span><span class="prelude-val">Some</span>(List(choices)) = <span class="kw-2">&amp;</span>param.args.choices {
<span class="kw">let </span>choices = choices
.iter()
.map(lit_to_string)
.collect::&lt;<span class="prelude-ty">Result</span>&lt;Vec&lt;<span class="kw">_</span>&gt;, <span class="kw">_</span>&gt;&gt;()<span class="question-mark">?</span>;

<span class="macro">quote::quote!</span> { <span class="macro">vec!</span>[#( ::poise::CommandParameterChoice {
name: ToString::to_string(<span class="kw-2">&amp;</span>#choices),
name: String::from(#choices),
localizations: Default::default(),
__non_exhaustive: (),
} ),<span class="kw-2">*</span>] }
Expand Down

0 comments on commit 868a341

Please sign in to comment.