Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truncate cannot remove first element #29

Open
davlum opened this issue Apr 16, 2021 · 1 comment
Open

truncate cannot remove first element #29

davlum opened this issue Apr 16, 2021 · 1 comment

Comments

@davlum
Copy link

davlum commented Apr 16, 2021

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?

@zowens
Copy link
Owner

zowens commented Apr 17, 2021

@davlum Good find! Can we add another method, and possibly truncate to the new method adjusting for the exclusion logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants