Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upcore: impl From<T> for Option<T> #34828
Conversation
rust-highfive
assigned
sfackler
Jul 14, 2016
sfackler
added
I-needs-decision
T-libs
labels
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Also see rust-lang/rfcs#1402 and #33170 |
This comment has been minimized.
This comment has been minimized.
|
I know it's been discussed a bunch before. Having the impl exist by itself doesn't mean the APIs need to use it. |
This comment has been minimized.
This comment has been minimized.
|
Indeed, thanks for the cc @jonas-schievink! @seanmonstar this has been discussed and turned down before, do you have new information which has changed since the decision was last made? If not we can probably just close this. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton a difference to the previous PR is that this only adds the The choice to alter APIs to use that is not made in this PR, and so the standard library does not need to worry about stabilizing "optional arguments" in itself that could conflict with lang features. |
This comment has been minimized.
This comment has been minimized.
|
Here's a longer rationale: I don't see these as "optional arguments" in the usual sense. I have several arguments that are definitely not optional, they must have an answer, but whether that answer has a value, or a Optional arguments look like this: fn action(&mut self, action: Action, dur: Option<Duration> = None) {
}
thing.action(Action::Read); // same as thing.action(Action::Read, None)Instead, I have methods that do not make sense to have this form of "optional arguments": fn timeout(&mut self, dur: Option<Duration>) {
}
thing.timeout(); // this would not make sense
thing.timeout(None); // you must give an answer
thing.timeout(Some(10));The point with this method is to specify if there should be a timeout, and if so, for how long. It does not make sense for this to have a signature of So, what to do. Seems there's 4 options.
|
This comment has been minimized.
This comment has been minimized.
|
The fact that we have 2 issues and 2 PRs for exactly the same thing (and without any of the optional arguments stuff, although I see it being as a primary motivation), proves that it is a very desired feature, even without some implementation of optional arguments. I know I wanted it for something that’s not optional arguments in some generic code. |
This comment has been minimized.
This comment has been minimized.
Turned down without any motivation except for vague concerns about possible future language features. |
This comment has been minimized.
This comment has been minimized.
|
From my recollection, the concerns were over modifications to the timeout APIs in particular. The |
This comment has been minimized.
This comment has been minimized.
|
I think the concern here is that library authors will start using this feature for optional arguments. Then, if rust ever adds built-in optional/default argument support, there'll be two different ways to do it. (Note: I'm still in favor of this feature). |
This comment has been minimized.
This comment has been minimized.
|
Yes it sounds like this is different than #33170 in that it's not proposing the standard library uses it for optional arguments, but the motivation is still optional arguments in external libraries. Adding the |
This comment has been minimized.
This comment has been minimized.
|
We discussed this during libs triage today and the decision was to merge given that this PR is only adding a |
This comment has been minimized.
This comment has been minimized.
|
@bors: r+ Thanks again for the PR @seanmonstar! |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jul 19, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Tue, Jul 19, 2016 at 12:50 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jul 20, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Tue, Jul 19, 2016 at 9:23 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
@bors: r- Looks like travis failure is legitimate |
alexcrichton
removed
the
I-needs-decision
label
Jul 20, 2016
seanmonstar
force-pushed the
seanmonstar:into-opton
branch
from
501c615
to
fbfee42
Jul 20, 2016
This comment has been minimized.
This comment has been minimized.
|
Added |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jul 21, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Wed, Jul 20, 2016 at 6:04 PM, bors notifications@github.com wrote:
|
seanmonstar commentedJul 14, 2016
First, the semantics of this
implseem spot on. If I have a valueT, and I wish to make aOption<T>, thenOption::from(val)should always giveSome(val).Second, this allows improvement for several APIs that currently take
Option<T>as arguments. Consider:With this
impl:The change to those methods aren't included, but could be modified later.
r? @sfackler