Skip to content

Multiple errors in getopt example #1833

Closed
@mcandre

Description

@mcandre

The getopt example in the docs has several errors which prevent it, and any code based on it, from running.

getopttest.rs based on the docs

getopttest2.rs resolved multiple errors

For instance, the example code attempts to shift the CLI arguments in order to drop the program name and pass the rest into the getopt parser. But the way the example code uses vec::shift is incorrect. This function indeed drops the first element, but it returns the element, not the rest of the vector.

The example code neglects to inform coders how to properly import the various getopt functions (there are several), and how to import the maybe type (opt_maybe_str).

Finally, the example code fails to operate due to the nature of vec::shift; even when used properly according to the docs, this function is designed for mutable vectors, not the constant vector of CLI arguments. A better choice is vec::tail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions