Skip to content

String::truncate() and Vec::truncate() are inconsistent if new_len > current length #32717

@Dr-Emann

Description

@Dr-Emann

String::truncate specifies that it "panics if new_len > current length"
Vec::truncate specifies that "If len is greater than the vector's current length, this has no effect.

This seems very inconsistent. I would personally prefer Vec's semantics. I'm not sure if it's a breaking change to add/remove a documented panic, and I fear it's not okay, but it feels very inconsistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions