-
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: extension trait conventions #445
RFC: extension trait conventions #445
Conversation
Should we be conflating all the different kinds of extension here? There's extension traits for:
Obviously, these lines are a bit blurry. Overall I like the recommendation (distinguish traits for generic programming from other traits with a simple suffix), I just want to be sure we aren't conflating unrelated concepts. |
@gankro Thanks for the feedback! Here are some thoughts broken down by your categories:
Eventually, this will be handled by
I've long wished we could do this another way, but there hasn't been a strong enough justification for the work, yet. That said, there's a separate
These two are very closely related, since in general the blanket impl you provide when breaking out an object safe trait is actually adding methods to types defined elsewhere.
I've sometimes thought the same thing, but actually many of these traits do end up used for generic programming (for better or worse). The other thing is, these operator traits are "generic" in the sense that they apply to a large (unbounded) number of new types, whereas most extension traits are designed to apply to a single, or small family, of known types. So the "generic" aspect doesn't just mean generics in the technical sense, but also in a more fuzzy design sense. In short, I think having just the |
|
This is an initial pass at stabilizing the `iter` module. The module is fairly large, but is also pretty polished, so most of the stabilization leaves things as they are. Some changes: * Due to the new object safety rules, various traits needs to be split into object-safe traits and extension traits. This includes `Iterator` itself. While splitting up the traits adds some complexity, it will also increase flexbility: once we have automatic impls of `Trait` for trait objects over `Trait`, then things like the iterator adapters will all work with trait objects. * Iterator adapters that use up the entire iterator now take it by value, which makes the semantics more clear and helps catch bugs. Due to the splitting of Iterator, this does not affect trait objects. If the underlying iterator is still desired for some reason, `by_ref` can be used. (Note: this change had no fallout in the Rust distro except for the useless mut lint.) * In general, extension traits new and old are following an [in-progress convention](rust-lang/rfcs#445). As such, they are marked `unstable`. * As usual, anything involving closures is `unstable` pending unboxed closures. * A few of the more esoteric/underdeveloped iterator forms (like `RandomAccessIterator` and `MutableDoubleEndedIterator`, along with various unfolds) are left experimental for now. * The `order` submodule is left `experimental` because it will hopefully be replaced by generalized comparison traits. * "Leaf" iterators (like `Repeat` and `Counter`) are uniformly constructed by free fns at the module level. That's because the types are not otherwise of any significance (if we had `impl Trait`, you wouldn't want to define a type at all). Closes rust-lang#17701 Due to renamings and splitting of traits, this is a: [breaking-change]
This is an initial pass at stabilizing the `iter` module. The module is fairly large, but is also pretty polished, so most of the stabilization leaves things as they are. Some changes: * Due to the new object safety rules, various traits needs to be split into object-safe traits and extension traits. This includes `Iterator` itself. While splitting up the traits adds some complexity, it will also increase flexbility: once we have automatic impls of `Trait` for trait objects over `Trait`, then things like the iterator adapters will all work with trait objects. * Iterator adapters that use up the entire iterator now take it by value, which makes the semantics more clear and helps catch bugs. Due to the splitting of Iterator, this does not affect trait objects. If the underlying iterator is still desired for some reason, `by_ref` can be used. (Note: this change had no fallout in the Rust distro except for the useless mut lint.) * In general, extension traits new and old are following an [in-progress convention](rust-lang/rfcs#445). As such, they are marked `unstable`. * As usual, anything involving closures is `unstable` pending unboxed closures. * A few of the more esoteric/underdeveloped iterator forms (like `RandomAccessIterator` and `MutableDoubleEndedIterator`, along with various unfolds) are left experimental for now. * The `order` submodule is left `experimental` because it will hopefully be replaced by generalized comparison traits. * "Leaf" iterators (like `Repeat` and `Counter`) are uniformly constructed by free fns at the module level. That's because the types are not otherwise of any significance (if we had `impl Trait`, you wouldn't want to define a type at all). Closes #17701 Due to renamings and splitting of traits, this is a: [breaking-change]
People are running into problems because the extension traits tend to have a blanket implementation (e.g. here, It is easy to come up with better implementations that the default, for example |
When we get opt-out traits (#19) it might be possible to define something like |
I see the problem that |
Rename extension traits as per rust-lang/rfcs#445
This is a conventions RFC establishing a definition and naming
convention for extension traits:
FooExt
.Rendered