serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
653 stars 114 forks source link

support destructuring patterns in `poise::command` macro #158

Closed y21 closed 1 year ago

y21 commented 1 year ago

It would be nice if destructuring patterns were supported for parameters in functions annotated with the #[poise::command] macro. That is, this currently does not compile (as it only accepts identifier patterns atm):

#[poise::command(prefix_command, track_edits, broadcast_typing)]
pub async fn foo(cx: PoiseContext<'_>, CodeBlock { code, .. }: CodeBlock) -> anyhow::Result<()> {
  // ...
  Ok(())
}

It's not particularily important I suppose, one can always just write let CodeBlock { code, .. } = block; in the body (or access struct fields manually) but it would be a nice-to-have :)

kangalio commented 1 year ago

The reason I omitted support for destructuring patterns is that there is no clear parameter name anymore.

Thinking about it, you technically don't need it for text commands. So I guess CommandParameter.name could be made optional. Not sure if it's worth the extra complexity