-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Stabilize std::prelude #503
Conversation
Stabilize the `std::prelude` module by removing some of the less commonly used functionality of it.
cc #497, an RFC specifically about |
Assuming that user-defined preludes need to be opted into, the syntax for that could be |
That doesn't quite give you the effect of the prelude, because it applies only to the current scope. There are some proposals in the works for allowing you to specify a custom prelude in your crate root that will be wholly imported into all scopes within the crate. A feature like this would make it relatively easy to make "changes" to the |
I am 👍 for this. |
// Rust code. Implementors of the `Ord` and `PartialOrd` traits will likely be | ||
// required to import these names, but it is not expected that Rust code at | ||
// large will require these names to be in the prelude. | ||
pub use cmp::Ordering::{mod, Less, Equal, Greater}; |
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.
mod
Is this a typo?
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.
Nope, it imports the Ordering
enum, like cmp::{mod, Ordering}
would import cmp
and cmp::Ordering
.
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.
woah awesome, TIL
// The prelude will be responsible for providing unicode-respecting methods on
// primitives while requiring that ascii-specific manipulation is imported
// manually. I'm skeptical of providing Unicode-respecting methods in the prelude, because the operations are so complicated, with locale-dependence and many choices to make. It might be better to require the user to specify, via imports, which flavor of operations they're using. There are a lot of formats (like HTTP and HTML) that use machine-interpreted text with ASCII-case-insensitive matching. This is a subtly different data type from "text written by humans for human consumption", but it's not worth forking |
// While currently present in the prelude, these traits do not need to be in
// scope to use the language syntax associated with each trait. These traits are
// also only rarely used in bounds on generics and are consequently
// predominately used for `impl` blocks. Due to this lack of need to be included
// into all modules in Rust, these traits are all removed from the prelude.
...
pub use ops::{Deref, DerefMut}; Because of rust-lang/rust#15609, it is sometimes necessary to introduce an explicit |
I disagree with "just as likely". You and I use ASCII-only case-insensitive matching routinely, but it’s fairly domain-specific: it only makes senses in a namespace like HTML element names where every "valid" name is ASCII, it’s just wrong on full Unicode text. It definitely should not be in the prelude. As to Unicode case folding, some variations of it are locale-independent. Sure, they’re also wrong for the a few cases like the dotted/dotless iİıI in Turkish, but they’re much less wrong than ASCII-only. ( I think that some people will want to "just do XYZ" and not care about Unicode subtleties, much less being forced to specify a content language (which might just end up hard-coded to |
@kmcallister right now we are quite strict about I expect we will very clearly document precisely what |
// will be removed from the prelude (and soon moved to std::sync as well). | ||
// | ||
// Additionally, while spawning a new thread is a common operation in concurrent | ||
// programming, it is nota frequent operation in code in general. For example |
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.
nota => not a
The discussion here seems to be slowing down, so I may try to look to merge this soon. ping @kmcallister about unicode in the prelude |
I think we should do it, yes (probably Broader context for others reading: we hope to eventually allow you to specify a custom prelude at the top of your crate (which would be glob imported everywhere, just as If we don't introduce internal namespacing like this, there would not be a clear place for new prelude versions to go. On the other hand, if we never end up evolving the prelude in this way, having |
I'm sitting on a proposal that should hopefully eliminate much of the need for third party preludes and the addition of anything to the libstd prelude, but sticking the current prelude in a |
@sfackler Interesting! FWIW, the plan I had in mind was roughly to add a Curious to hear what you have in mind! |
The tl;dr is to provide a way of marking a trait impl as always being in scope (e.g. In any case, it's a pretty clear post-1.0 improvement, so I'm not planning on writing it up formally until after the initial release. |
@sfackler Ah ok, we've discussed that in the past. I don't think that completely covers what preludes offer, but it would certainly help! |
I've pushed an update which recommends |
Collections Reform v1 adds |
@gankro I think for the alpha, we're going to leave |
While there has been surprisingly little discussion on this RFC thread, it's been brought up in the meeting and seen fairly widely in the community, and we need to move forward before the alpha. The core team has reviewed the RFC and is happy with the direction it's taking. We will also have an opportunity to tweak the exact contents before beta/1.0. |
Stabilize the
std::prelude
module by removing some of the less commonly usedfunctionality of it.
Rendered