Skip to content

truncate cannot remove first element #29

@davlum

Description

@davlum

Truncate deletes all entries after offset. This makes it impossible to remove the first element, because it is retained even when truncate(0). I believe it is for this reason that truncate on Vec also truncates the element passed.

fn main() {
    let mut vec = vec![1,2,3];
    vec.truncate(0);
    println!("{:?}", vec);
}

>>> []

I'd be happy to open a PR on this if I knew what direction you wanted to take it. New method or update the old one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions