Skip to content

Commit c6a06d9

Browse files
committed
collapse into single-line paragraphs
github markdown makes newlines significant
1 parent 27643b2 commit c6a06d9

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

text/0000-return-type-notation.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
# Summary
99
[summary]: #summary
1010

11-
Return type notation (RTN) gives a way to reference or bound the type returned by a trait method.
12-
The new bounds look like `T: Trait<method(..): Send>` or `T::method(..): Send`.
13-
The primary use case is to add bounds such as `Send` to the futures returned by `async fn`s in traits and `-> impl Future` functions, but they work for any trait function defined with return-position impl trait (e.g., `where T: Factory<widgets(..): DoubleEndedIterator>` would also be valid).
11+
Return type notation (RTN) gives a way to reference or bound the type returned by a trait method. The new bounds look like `T: Trait<method(..): Send>` or `T::method(..): Send`. The primary use case is to add bounds such as `Send` to the futures returned by `async fn`s in traits and `-> impl Future` functions, but they work for any trait function defined with return-position impl trait (e.g., `where T: Factory<widgets(..): DoubleEndedIterator>` would also be valid).
1412

1513
This RFC proposes a new kind of type written `<T as Trait>::method(..)` (or `T::method(..)` for short). RTN refers to "the type returned by invoking `method` on `T`".
1614

@@ -123,8 +121,7 @@ But this `SendService` trait is too strong for use outside a work-stealing setup
123121

124122
## Comparison to an analogous problem with `IntoIterator`
125123

126-
It is useful to compare this situation with analogous scenarios that arise elsewhere in Rust, such as with associated types. Imagine a function that takes an `I: IntoIterator`
127-
and which wishes to make use of the returned iterator in a separate thread:
124+
It is useful to compare this situation with analogous scenarios that arise elsewhere in Rust, such as with associated types. Imagine a function that takes an `I: IntoIterator` and which wishes to make use of the returned iterator in a separate thread:
128125

129126
```rust
130127
fn into_iter_example<I: IntoIterator>(i: I) {
@@ -166,20 +163,13 @@ There are two ways the function `into_iter_example` could be made to compile:
166163
1. Modify the `IntoIterator` trait to require that the target iterator type is *always* `Send`
167164
2. Modify the function to have a where-clause `I::IntoIter: Send`.
168165

169-
The 1st option is less flexible but more convenient;
170-
it is inappropriate in a highly generic trait like `IntoIterator` which is used in a number of scenarios.
171-
It would be fine for an application- or library-specific crate that is only used in narrow circumstances.
172-
Referring back to the compiler's error message, you can see that an additional where-clause is exactly what it suggested.
166+
The 1st option is less flexible but more convenient; it is inappropriate in a highly generic trait like `IntoIterator` which is used in a number of scenarios. It would be fine for an application- or library-specific crate that is only used in narrow circumstances. Referring back to the compiler's error message, you can see that an additional where-clause is exactly what it suggested.
173167

174-
This is the challenge: **Rust does not currently have a way to write the equivalent of `where I::IntoIter: Send` for the futures returned by `async fn` (or the results of `-> impl Trait` methods in traits).**
175-
This creates a gap between the first `Service` example, which can only be resolved by modifying the trait,
176-
and `IntoIterator`, which can be resolved either by modifying the trait or by adding a where-clause to the function,
177-
whichever is more appropriate.
168+
This is the challenge: **Rust does not currently have a way to write the equivalent of `where I::IntoIter: Send` for the futures returned by `async fn` (or the results of `-> impl Trait` methods in traits).** This creates a gap between the first `Service` example, which can only be resolved by modifying the trait, and `IntoIterator`, which can be resolved either by modifying the trait or by adding a where-clause to the function, whichever is more appropriate.
178169

179170
## Return type notation (RTN) permits the return type of AFIT and RPITIT to be bounded, closing the gap
180171

181-
The core feature proposed in this RFC is the ability to write a bound that bounds the return type of an AFIT/RPITIT trait method.
182-
This allows the `spawn_call` definition to be amended to require that `call()` returns a `Send` future:
172+
The core feature proposed in this RFC is the ability to write a bound that bounds the return type of an AFIT/RPITIT trait method. This allows the `spawn_call` definition to be amended to require that `call()` returns a `Send` future:
183173

184174
```rust
185175
async fn spawn_call<S>(service: S) -> S::Response
@@ -201,9 +191,7 @@ A variant of the proposal in this RFC is already implemented, so you can [try th
201191

202192
## RTN is useful for more than `Send` bounds
203193

204-
RTN is useful for more than `Send` bounds.
205-
For example, consider the trait `Factory`,
206-
which contains a method that returns an `impl Iterator`:
194+
RTN is useful for more than `Send` bounds. For example, consider the trait `Factory`, which contains a method that returns an `impl Iterator`:
207195

208196
```rust
209197
trait Factory {

0 commit comments

Comments
 (0)