Skip to content

The documentation of Vec contradicts itself regarding with_capacity #101316

Open
@Kixunil

Description

Location

https://doc.rust-lang.org/std/vec/struct.Vec.html

Summary

In section Guarantees the documentation says:

vec![x; n], vec![a, b, c, d], and Vec::with_capacity(n), will all produce a Vec with exactly the requested capacity.

However in Vec::with_capacity(n) it says:

This method is allowed to allocate for more elements than capacity.

And

If it is imporant to know the exact allocated capacity of a Vec, always use the capacity method after construction.

These clearly contradict each-other. I guess it's better for performance to not guarantee capacity but maybe it'd break someones code to change it since it was already "documented". :(

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions