2 ms·
Go 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
by viraptor 8y ago
Go 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.