Skip to content

Use ? operator instead of unwrap in all examples/docs #836

Open
@sunjay

Description

@sunjay

In the Rust API Guidelines, it talks about how we should prefer to use the ? operator instead of unwrap() in our examples/docs because people often copy/paste directly from the docs. (See the full justification at that link.)

Since main() can now return a Result we can actually do this everywhere.

I know rust-sdl2 has been around for much longer than these features, so I'm wondering if you would even be interested in someone (maybe even me!) doing the work to convert all of the examples to use the ? operator.

Doing this conversion actually reveals some interesting things like how there are inconsistencies in the error types returned by the methods. Most methods return an error type of String but some don't and this makes using ? absolutely everywhere hard. Part of this work could be unifying everything under a single SDLError error type. (Maybe better completed separately since it's a breaking change.)

Any line that can't be converted to use ? instead of unwrap should at least use expect with a nice message so people know what happened.

Checklist

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions