@@ -41,8 +41,7 @@ programs is entirely unaffected.
41
41
42
42
The most important additions are a postfix ` ? ` operator for propagating
43
43
"exceptions" and a ` try ` ..` catch ` block for catching and handling them. By an
44
- "exception", we essentially just mean the ` Err ` variant of a ` Result ` . (See the
45
- "Detailed design" section for more precision.)
44
+ "exception", for now, we essentially just mean the ` Err ` variant of a ` Result ` .
46
45
47
46
48
47
## ` ? ` operator
@@ -106,7 +105,7 @@ error types which may be propagated:
106
105
Here ` io::Error ` and ` json::Error ` can be thought of as subtypes of ` MyError ` ,
107
106
with a clear and direct embedding into the supertype.
108
107
109
- The ` ? ` operator should therefore perform such an implicit conversion in the
108
+ The ` ? ` operator should therefore perform such an implicit conversion, in the
110
109
nature of a subtype-to-supertype coercion. The present RFC uses the
111
110
` std::convert::Into ` trait for this purpose (which has a blanket ` impl `
112
111
forwarding from ` From ` ). The precise requirements for a conversion to be "like"
@@ -150,8 +149,8 @@ There are two variations on this theme:
150
149
}
151
150
152
151
Here the ` catch ` performs a ` match ` on the caught exception directly, using
153
- any number of refutable patterns. This form is convenient for checking and
154
- handling the caught exception directly .
152
+ any number of refutable patterns. This form is convenient for handling the
153
+ exception in-place .
155
154
156
155
157
156
# Detailed design
@@ -274,12 +273,12 @@ are merely one way.
274
273
275
274
Deep:
276
275
277
- match 'here: {
276
+ match ( 'here: {
278
277
Ok(match foo() {
279
278
Ok(a) => a,
280
279
Err(e) => break 'here Err(e.into())
281
280
}.bar())
282
- } {
281
+ }) {
283
282
Ok(a) => a,
284
283
Err(e) => match e {
285
284
A(a) => baz(a),
@@ -342,7 +341,7 @@ Among the considerations:
342
341
* Simplicity. Brevity.
343
342
344
343
* Following precedent from existing, popular languages, and familiarity with
345
- respect to analogous constructs in them .
344
+ respect to their analogous constructs.
346
345
347
346
* Fidelity to the constructs' actual behavior. For instance, the first clause
348
347
always catches the "exception"; the second only branches on it.
@@ -370,7 +369,7 @@ Two obvious, minimal requirements are:
370
369
The other requirements for an implicit conversion to be well-behaved in the
371
370
context of this feature should be thought through with care.
372
371
373
- Some further thoughts and possibilities on this matter:
372
+ Some further thoughts and possibilities on this matter, only as brainstorming :
374
373
375
374
* It should be "like a coercion from subtype to supertype", as described
376
375
earlier. The precise meaning of this is not obvious.
@@ -379,20 +378,20 @@ Some further thoughts and possibilities on this matter:
379
378
compound-coerce to go from ` A ` to ` Z ` indirectly along multiple different
380
379
paths, they should all have the same end result.
381
380
382
- * It should be unambiguous, or preserve the meaning of the input:
383
- ` impl From<u8> for u32 ` as ` x as u32 ` feels right; as ` (x as u32) * 12345 `
384
- feels wrong, even though this is perfectly pure, total, and injective. What
385
- this means precisely in the general case is unclear.
386
-
387
381
* It should be lossless, or in other words, injective: it should map each
388
382
observably-different element of the input type to observably-different
389
383
elements of the output type. (Observably-different means that it is possible
390
384
to write a program which behaves differently depending on which one it gets,
391
385
modulo things that "shouldn't count" like observing execution time or
392
386
resource usage.)
393
387
388
+ * It should be unambiguous, or preserve the meaning of the input:
389
+ ` impl From<u8> for u32 ` as ` x as u32 ` feels right; as ` (x as u32) * 12345 `
390
+ feels wrong, even though this is perfectly pure, total, and injective. What
391
+ this means precisely in the general case is unclear.
392
+
394
393
* The types converted between should the "same kind of thing": for instance,
395
- the * existing* ` impl From<u32> for Ipv4Addr ` is pretty suspect on this count.
394
+ the * existing* ` impl From<u32> for Ipv4Addr ` feels suspect on this count.
396
395
(This perhaps ties into the subtyping angle: ` Ipv4Addr ` is clearly not a
397
396
supertype of ` u32 ` .)
398
397
@@ -566,8 +565,8 @@ below.)
566
565
The ` translate ` method says that it should be possible to translate to any
567
566
* other* ` ResultCarrier ` type which has the same ` Normal ` and ` Exception ` types.
568
567
This may not appear to be very useful, but in fact, this is what can be used to
569
- inspect the result, by translating it to a concrete type such as `Result<Normal,
570
- Exception>` and then, for example, pattern matching on it.
568
+ inspect the result, by translating it to a concrete, known type such as
569
+ ` Result<Normal, Exception>` and then, for example, pattern matching on it.
571
570
572
571
Laws:
573
572
0 commit comments