66# Summary
77[ summary ] : #summary
88
9- An alternative postfix syntax for match expressions that allows for interspercing match statements with function chains
9+ An alternative postfix syntax for match expressions that allows for interspersing match statements with function chains
1010
1111``` rust
1212foo . bar (). baz. match {
@@ -31,11 +31,11 @@ of the code.
3131
3232Sometimes, these method chains can become quite terse for the sake of composability
3333
34- Forever we hear the complaints of fresh rustaceans learning about option/result
35- method chaining being [ very surprised by the ordering ] ( https://github.com/rust-lang/rfcs/issues/1025 ) of the methods like
34+ For instance, we have the [ surprising ordering ] ( https://github.com/rust-lang/rfcs/issues/1025 )
35+ of the methods like
3636[ ` map_or_else ` ] ( https://doc.rust-lang.org/std/result/enum.Result.html#method.map_or_else ) .
3737
38- This RFC proposes promoting the use of match statements by supporting postfix-match, reducing the use of some of these methods terse and potentially confusing method chains.
38+ This RFC proposes promoting the use of match statements by supporting postfix-match, reducing the use of some of these terse methods and potentially confusing method chains.
3939
4040# Guide-level explanation
4141[ guide-level-explanation ] : #guide-level-explanation
@@ -46,9 +46,9 @@ variant. Some powerful techniques like pattern binding, nested patterns and or p
4646allow for some versatile and concise, but still fairly readable syntax for dealing
4747with these types.
4848
49- Rust often features functional approachs to lots of problems. For instance,
49+ Rust often features functional approaches to lots of problems. For instance,
5050it's very common to have chains of ` map ` , ` and_then ` , ` ok_or ` , ` unwrap `
51- to process some ` Option ` or ` Result ` type in a pipeline, rather than continously reassigning to new variable bindings.
51+ to process some ` Option ` or ` Result ` type in a pipeline, rather than continuously reassigning to new variable bindings.
5252
5353``` rust
5454let x = Some (42 );
@@ -59,7 +59,7 @@ let magic_number = x.map(|x| x * 5)
5959```
6060
6161Some of these provided method chains are fairly readable, like the ones presented above,
62- but sometimes the desire to use long method chains is met with unweildy hacks or awkward function arguments.
62+ but sometimes the desire to use long method chains is met with unwieldy hacks or awkward function arguments.
6363
6464``` rust
6565let x = Some (" crustaceans" );
@@ -201,7 +201,7 @@ context.client
201201 . await
202202 . match {
203203 Err (_ ) => Ok (" Ferris" ),
204- Ok (resp ) => resp . json :: <Option < String > >(). await ,
204+ Ok (resp ) => resp . json :: <String >(). await ,
205205 // this works in a postfix-match ^^^^^^
206206 }
207207```
@@ -254,12 +254,12 @@ make the language more flexible such that match statements aren't a hindrance.
254254
255255### Postfix Macros
256256
257- [ postfix macros] ( https://github.com/rust-lang/rfcs/pull/2442 ) have been an idea for many years now. If they were to land, this feature
258- could easily be implemented as a macro (bikeshedding on postfix macro syntax) :
257+ [ postfix macros] ( https://github.com/rust-lang/rfcs/pull/2442 ) have been an idea for many years now.
258+ If they were to land, this feature could easily be implemented as a macro:
259259
260260``` rust
261261macro match_! (
262- postfix { $ (
262+ { $ self : expr ; $ (
263263 $ arm : pat => $ body : expr ,
264264 )+ } => {
265265 match $ self { $ (
@@ -275,10 +275,19 @@ still not close to agreeing on syntax or behaviour.
275275### Pipes
276276
277277I've already mentioned [ tap] ( #tap-pipelines ) for how we can do prefix-in-postfix,
278- so we could promote the use of ` .pipe ` instead. However, using the pipe method makes
278+ so we could promote the use of ` .pipe() ` instead. However, using the pipe method makes
279279async awkward and control flow impossible.
280280
281- Alternatively we could have a new builtin pipeline operator
281+ ``` rust
282+ x . pipe (| x | async {
283+ match x {
284+ Err (_ ) => Ok (" Ferris" ),
285+ Ok (resp ) => resp . json :: <String >(). await ,
286+ }
287+ }). await
288+ ```
289+
290+ We could add a new builtin pipeline operator
282291(e.g. ` |> ` <sup >[ 0] </sup > or ` .let x {} ` ><sup >[ 1] </sup >)
283292but this is brand new syntax and requires a whole new set of discussions.
284293
@@ -304,7 +313,7 @@ I've heard many accounts from people that postfix-await is one of their favourit
304313
305314Method call chains will not lifetime extend their arguments. Match statements, however,
306315are notorious for having lifetime extension. It is currently unclear if promoting these
307- usecases of match would cause more [ subtle bugs] ( https://fasterthanli.me/articles/a-rust-match-made-in-hell#my-actual-bug ) , or if it's negligable
316+ use-cases of match would cause more [ subtle bugs] ( https://fasterthanli.me/articles/a-rust-match-made-in-hell#my-actual-bug ) , or if it's negligible
308317
309318# Future possibilities
310319[ future-possibilities ] : #future-possibilities
0 commit comments