Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.
This repository was archived by the owner on May 21, 2024. It is now read-only.

Argument parsing for required and optional arguments should have a flexible order  #31

@arqunis

Description

@arqunis

The current argument parsing system for commands enforces a strict order of the types of arguments, which proceeds as:

  1. Required arguments
  2. Optional arguments
  3. Variadic argument or #[rest] argument

Each type of argument may be absent, but violating this order will result in a macro error. What this issue proposes, however, is to break the strict order for required and optional arguments. This would allow for backtracking when parsing arguments for a command.

For example, for the following command:

#[command]
async fn boogie(ctx: FrameworkContext, msg: &Message, user2: Option<UserId>, user: UserId) -> CommandResult {
    // ....
}

no error would originate from the macro. Instead, if just one argument is given, user2 will be None, while user will be populated with the argument. And in the case of two arguments, user2 will be the first argument, and user the second argument.

Order between required/optional arguments and a variadic/#[rest] argument will stay the same and will have to be uphold.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestProposition for a new feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions