-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC for pre-1.0 prelude additions #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
- Feature Name: NA | ||
- Start Date: 2015-04-03 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
Add `Default`, `IntoIterator` and `ToOwned` trait to the prelude. | ||
|
||
# Motivation | ||
|
||
Each trait has a distinct motivation: | ||
|
||
* For `Default`, the ergonomics have vastly improved now that you can | ||
write `MyType::default()` (thanks to UFCS). Thanks to this | ||
improvement, it now makes more sense to promote widespread use of | ||
the trait. | ||
|
||
* For `IntoIterator`, promoting to the prelude will make it feasible | ||
to deprecate the inherent `into_iter` methods and directly-exported | ||
iterator types, in favor of the trait (which is currently redundant). | ||
|
||
* For `ToOwned`, promoting to the prelude would add a uniform, | ||
idiomatic way to acquire an owned copy of data (including going from | ||
`str` to `String`, for which `Clone` does not work). | ||
|
||
# Detailed design | ||
|
||
* Add `Default`, `IntoIterator` and `ToOwned` trait to the prelude. | ||
|
||
* Deprecate inherent `into_iter` methods. | ||
|
||
* Ultimately deprecate module-level `IntoIter` types (e.g. in `vec`); | ||
this may want to wait until you can write `Vec<T>::IntoIter` rather | ||
than `<Vec<T> as IntoIterator>::IntoIter`. | ||
|
||
# Drawbacks | ||
|
||
The main downside is that prelude entries eat up some amount of | ||
namespace (particularly, method namespace). However, these are all | ||
important, core traits in `std`, meaning that the method names are | ||
already quite unlikely to be used. | ||
|
||
Strictly speaking, a prelude addition is a breaking change, but as | ||
above, this is highly unlikely to cause actual breakage. In any case, | ||
it can be landed prior to 1.0. | ||
|
||
# Alternatives | ||
|
||
None. | ||
|
||
# Unresolved questions | ||
|
||
The exact timeline of deprecation for `IntoIter` types. | ||
|
||
Are there other traits or types that should be promoted before 1.0? |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to consider removing these methods entirely actually as it's difficult to call a trait method instead of an inherent method sometimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, otherwise it would be quite painful to avoid the deprecation warnings.
That makes this even more of a "technically breaking" change, but again I suspect no code will actually break. Maybe a good trial for @brson's tool!