On Mon, Dec 9, 2013 at 10:53 AM, Damien Radtke <[email protected]> wrote: > I have no idea if it would be feasible in the standard library, but wouldn't > the ideal solution be having one function (e.g. from_utf8()) that could > return two possible values, a bare result and an Option? Letting the > compiler decide which version to use based on type inference like this: > > let result: ~str = from_utf8(...); > let result: Option<~str> = from_utf8(...); > > Assuming both of them are passed invalid UTF8, then the first version would > fail, but the second version would just return None. > > Again, I don't know if it's possible given the current implementation, but I > do think it would be helpful to have a picture of the ideal, and then decide > on whatever solution comes closest. > > As a side note, even if the standard library sticks with two variants for > each option function, I would prefer the default one return an Option and > have the variant fail on invalid input. Task failure at runtime is a nastier > surprise than an invalid type error at compile time, especially for new > users who aren't entirely sure of the difference.
I think this is too complex and error prone. I don't see the problem with just using `Option` and then calling `get` (currently `unwrap`) when you want to ignore the possibility of failure. The compiler should be printing a failure stack trace but for now you can still get one with `gdb`. _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
