commitlog icon indicating copy to clipboard operation
commitlog copied to clipboard

truncate cannot remove first element

Open davlum opened this issue 3 years ago • 1 comments

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<T> 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?

davlum avatar Apr 16 '21 19:04 davlum

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

zowens avatar Apr 17 '21 03:04 zowens