Declares a macro that turns the ::()
postfix operator into a general postfix operator.
Mostly by re-defining structures from the syn
for parsing.
```rust
use sonicspin::sonicspin;
sonicspin! { let res = 0::(match) { x => x + 2 }::(match) { x => x + 10 }; asserteq!(res, 12);
let mut acc = 0;
(0..3)::(for _ in) {
acc += 1;
};
assert_eq!(acc, 3);
} ```
See tests/
for further examples.
Given some of the many discussions regarding the await
syntax and the resulting possibility of general postfix operators, this crate explores such possibility with the "sonic-spin" operator (::()
).
If the await syntax turned out to be "prefix await" await expr
, then this crate would enable the syntax expr::(await)
similarly to the ?
postfix operator.
Some of the mentioned discussions: - https://internals.rust-lang.org/t/idea-universal-pipelining-a-k-a-making-await-generic/9973 - https://github.com/rust-lang/rfcs/pull/2442
For piped operations, see the tests/common.rs::Pipe
trait and it's usage in tests/if.rs::if_pipe
function. ie. sonic-spin is not required for such operations.
This is a draft and is based on this suggestion:
https://github.com/rust-lang/rfcs/issues/2698