Hi, Just a suggestion, don't know what it's worth...
For the "not helpful error message" thing, couldn't we extend the option API, to be able to specify at the creation of a None value the error string that will be displayed if one calls unwrap() on this value ? This may be useful in several situations. Leo Le 6 déc. 2013 à 21:48, Corey Richardson <[email protected]> a écrit : > I'm in favor of this but it makes things less "pretty". Is the choice > really between pretty and fast? > > On Fri, Dec 6, 2013 at 3:41 PM, Simon Sapin <[email protected]> wrote: >> We have some functions and methods such as >> [std::str::from_utf8](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8.html) >> that may succeed and give a result, or fail when the input is invalid. >> >> 1. Sometimes we assume the input is valid and don’t want to deal with the >> error case. Task failure works nicely. >> >> 2. Sometimes we do want to do something different on invalid input, so >> returning an `Option<T>` works best. >> >> And so we end up with both `from_utf8` and `from_utf8`. This particular case >> is worse because we also have `from_utf8_owned` and `from_utf8_owned_opt`, >> to cover everything. >> >> Multiplying names like this is just not good design. I’d like to reduce this >> pattern. >> >> Getting behavior 1. when you have 2. is easy: just call `.unwrap()` on the >> Option. I think we should rename every `foo_opt()` function or method to >> just `foo`, remove the old `foo()` behavior, and tell people (through >> documentation) to use `foo().unwrap()` if they want it back? >> >> The downsides are that unwrap is more verbose and gives less helpful error >> messages on task failure. But I think it’s worth it. >> >> What do you think? >> >> (PS: I’m guilty of making this worse in #10828, but I’d like to discuss this >> before sending pull requests with invasive API changes.) >> >> -- >> Simon Sapin >> _______________________________________________ >> Rust-dev mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/rust-dev > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
