@@ -178,8 +178,9 @@ With today's `trait_alias`, it wouldn't make much difference for `downstream`.
178
178
179
179
## Splitting a trait
180
180
181
- To exemplify this use-case, we will use [ Niko Matsakis’s proposal to split the
182
- ` Deref `
181
+ ### ` Deref ` → ` Receiver ` + ` Deref `
182
+
183
+ [ Niko Matsakis wants to split up the ` Deref `
183
184
trait] ( https://github.com/rust-lang/rust/pull/135881#issuecomment-2718417230 ) .
184
185
185
186
` Deref ` currently looks like this:
@@ -193,7 +194,23 @@ pub trait Deref {
193
194
```
194
195
195
196
Niko wants to split off the ` type Target ` part into a separate ` Receiver `
196
- supertrait. But there is no backward-compatible way to do this at present.
197
+ supertrait. But there is no good backward-compatible way to do this at present.
198
+
199
+ ### ` Iterator ` → ` LendingIterator ` + ` Iterator `
200
+
201
+ Once the necessary language features are stabilized, the library team will
202
+ likely want to add a ` LendingIterator ` trait to the standard library, that looks
203
+ like this:
204
+
205
+ ``` rust
206
+ pub trait LendingIterator {
207
+ type Item <'a > where Self : 'a ;
208
+ fn next (& mut self ) -> Option <Self :: Item <'_ >>;
209
+ }
210
+ ```
211
+
212
+ Ideally, every ` Iterator ` should automatically be a ` LendingIterator ` . But,
213
+ again, there is no good way to do this right now.
197
214
198
215
## Removing a ` Sized ` bound
199
216
@@ -324,6 +341,20 @@ impl QuiteVerboseAlias for () {
324
341
}
325
342
```
326
343
344
+ This could be used to add ` LendingIterator ` as a supertrait of ` Iterator ` , as
345
+ mentioned in the motivation section:
346
+
347
+ ``` rust
348
+ pub trait LendingIterator {
349
+ type Item <'a > where Self : 'a ;
350
+ fn next (& mut self ) -> Option <Self :: Item <'_ >>;
351
+ }
352
+
353
+ pub trait Iterator = for <'a > LendingIterator <Item <'a > = <Self as Iterator >:: Item > {
354
+ type Item ;
355
+ }
356
+ ```
357
+
327
358
## Implementing trait aliases for multiple traits
328
359
329
360
Trait aliases that combine multiple traits with ` + ` are also implementable:
@@ -975,11 +1006,10 @@ something when it does not.
975
1006
Anything that makes ` where ` clauses more powerful would make this feature more
976
1007
powerful as well.
977
1008
978
- For example:
979
-
980
- - If we could write bounds for the ` const ` ness of a method, that could allow
981
- emulating some of [ const traits] ( https://github.com/rust-lang/rfcs/pull/3762 ) —or
982
- even form part of the desugaring for that feature:
1009
+ For example, if we could write bounds for the ` const ` ness of a method, that
1010
+ could allow emulating some of [ const
1011
+ traits] ( https://github.com/rust-lang/rfcs/pull/3762 ) —or even form part of the
1012
+ desugaring for that feature:
983
1013
984
1014
``` rust
985
1015
pub trait PartialEq <Rhs = Self >
@@ -998,20 +1028,3 @@ where
998
1028
Self :: eq : const ,
999
1029
Self :: ne : const ; // 🚲🏠
1000
1030
```
1001
-
1002
- - If we could write a bound requiring that a GAT not use is lifetime, that could
1003
- enable retrofitting ` LendingIterator ` into ` Iterator ` :
1004
-
1005
- ``` rust
1006
- pub trait LendingIterator {
1007
- type Item <'a >
1008
- where
1009
- Self : 'a ;
1010
-
1011
- fn next (& mut self ) -> Option <Self :: Item <'_ >>;
1012
- }
1013
-
1014
- pub trait Iterator = Iterator
1015
- where
1016
- for <'a > Self :: Item <'a >: doesnt_depend_on <'a >; // 🚲🏠
1017
- ```
0 commit comments