Hacker News new | past | comments | ask | show | jobs | submit login

Let’s not go too far, Rust has plenty of panics at runtime.



Do you mean something that's not validated by the compiler, or explicit unwrap/panic calls?


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.


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.


The standard library provides safe downcasts on trait objects, which aren't all that dissimilar to Go interfaces.


Yes, 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: