Skip to content

Make square bracket [] more usable.Β #3583

Open
@crlf0710

Description

@crlf0710

TL;DR version: Make vec[key]_? = new_value; doesn't panic when key is out of bounds.

For Rust syntax budget, square bracket is perhaps one of the least rewarding current design at all. Every occurrence of square bracket reminds people the potential possibility of panicking. This might be suitable for the "error early if something goes wrong" style application, but for long running services, propagating the panic to the root of the thread callstack might not be a good idea.

This proposes putting an _(underscore) between the bracket and the ? operator to invoke new TryIndex{,Mut} traits instead, returning a Result with an error type, then perform ? operator on that to return early.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxSyntax related proposals & ideasT-langRelevant to the language team, which will review and decide on the RFC.T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions