5 ms·
Explicit unwrap/panic calls, as well as some numerical operations (in debug mode) that will panic on overflow. Indexing into arrays/slices outside bounds will a
by bluejekyll 8y ago
Explicit unwrap/panic calls, as well as some numerical operations (in debug mode) that will panic on overflow. Indexing into arrays/slices outside bounds will also panic.
This was in response to the point that Go panics, and I didn't think it was perfectly fair to use that as an example (I have others that I would use) since Rust also panics in similar situations.
- viraptor 8y agoGo does panic on a wrong interface cast, which doesn't have an equivalent in outside unsafe mode in rust, so I think it's a valid comparison. > as well as some numerical operations (in debug mode) that will panic on overflow That's a good thing. You normally want to find them in debug mode. > Indexing into arrays/slices outside bounds will also panic. Kind of. There's .get which returns an Option to do it safely, but you're right that basic indexing can fail.
- bluejekyll 8y agoYes, generally there are alternative interfaces for every one that panics that can be used to almost ensure that your code won't panic in Rust. As of today, that's by convention, not enforced by the compiler. There are situations where panicking is something you want to try and guard against, so I hope something like this gains traction and is able to be used more generally: https://crates.io/crates/no-panic https://crates.io/crates/no-panic
- burntsushi 8y agoThe standard library provides safe downcasts on trait objects, which aren't all that dissimilar to Go interfaces.