What is Nostr?
Jeff Martin /
npub1fvr…m20t
2024-03-12 23:29:31

Jeff Martin on Nostr: I just had a wild shower thought about #Rust / #RustLang : What if Rust had postfix ...

I just had a wild shower thought about #Rust / #RustLang :

What if Rust had postfix macros?

Something like:

let foo = bar().the_macro!();

where the postfix macro was able to transform its receiver somehow.

I often find myself writing boilerplate that looks something like:

let val = match foo() { Some(v) => v, None => { return; } };

But what if we could just do something like:

let val = foo().or! { return; };

I've always loved the Elvis operator in Kotlin that lets you do things like:

val foo = bar() ?: return

and I find myself reaching for something like that in Rust, but it's not there. Postfix macros might let you do something like that, and probably a whole lot more too. Maybe:

returns_a_result().warn_if_err!();

Something like the ? operator I guess, but more programmable.
Author Public Key
npub1fvr2n9j4qek28cdpnmxyh4w9l4ws7yr2xxdge7eug99al70p0snspwm20t