logoalt Hacker News

orlptoday at 8:46 AM1 replyview on HN

Vec::set_len is by no means deprecated. The lint you linked only covers a very specific unsound pattern using set_len.


Replies

kibwentoday at 9:16 AM

Indeed, and it doesn't need to be deprecated, because it's an API explicitly designed to give you low-level control where you need it, and because it is appropriately defined as an `unsafe` function with documented safety invariants that must be manually upheld in order for usage to be memory-safe. The documentation also suggests several other (safe) functions that should be used instead when possible, and provides correct usage examples: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.set... .

show 1 reply