google / google/zerocopy

`FromZeros::insert_vec_zeroed` both panics and returns `Result`

Open
#2,242 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

Fallible functions that also panic is a general API smell. [`insert_vec_zeroed`](https://docs.rs/zerocopy/0.8.14/zerocopy/trait.FromZeros.html#method.insert_vec_zeroed) mirrors [`std`'s](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.insert) panicking on index, but doesn't mirror the panicking allocation.

In the next breaking version, I propose that `insert_vec_zeroed` be made fully fallible by returning `Err` if `position > v.len()`.

Relevant: #1653

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.