| ▲ | dist1ll 3 hours ago | ||||||||||||||||
If that's the case then hats off. What you're describing is definitely not what I've seen in practice. In fact, I don't think I've ever seen a crate or production codebase that documents infallibility of every single slice access. Even security-critical cryptography crates that passed audits don't do that. Personally, I found it quite hard to avoid indexing for graph-heavy code, so I'm always on the lookout for interesting ways to enforce access safety. If you have some code to share that would be very interesting. | |||||||||||||||||
| ▲ | 10000truths 32 minutes ago | parent | next [-] | ||||||||||||||||
My rule of thumb is that unchecked access is okay in scenarios where both the array/map and the indices/keys are private implementation details of a function or struct, since an invariant is easy to manually verify when it is tightly scoped as such. I've seen it used it in: * Graph/tree traversal functions that take a visitor function as a parameter * Binary search on sorted arrays * Binary heap operations * Probing buckets in open-addressed hash tables | |||||||||||||||||
| ▲ | hansvm 2 hours ago | parent | prev [-] | ||||||||||||||||
> graph-heavy code Could you share some more details, maybe one fully concrete scenario? There are lots of techniques, but there's no one-size-fits-all solution. | |||||||||||||||||
| |||||||||||||||||