Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> You get the same problem with Rust's Result btw

How? Take the easy example, "clowns" is a string that's supposed to be an small integer. How do I get this wrong in Rust? We have to say what we want to happen when it won't parse which isn't ignoring it.

  let clowns: u16 = clowns.parse();   // Won't compile
If we say we believe this won't happen we can express that, but when it does happen the program panics...

  let clowns: u16 = clowns.parse().unwrap();   // Panics if clowns doesn't parse as a u16
We can say what we actually want to happen, but how is that the same problem?

  let clowns: u16 = clowns.parse().unwrap_or(1629);  // OK it's 1629 if it won't parse
Finally we can write the C-style "Nothing will go wrong" attitude using unsafe, but I don't see that as a problem, if your first instinct is to reach for unsafe Rust you're a bad programmer

  let clowns: u16 = unsafe { clowns.parse.unwrap_unchecked() }; // Mark Baum says "Boom".


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

Search: