Idea: |> operator for postfix calls to macros and free functions

So to clarify, my UMCS (Unified Method Call Syntax) proposal from the other thread is that when resolving recv.fun(args..) the compiler fails to find any inherent or trait impls (including with deref…) then it will try resolve it as a free function fun(recv, args..) instead.

The standard method syntax being:

  1. method – recv.fun(args..)

The following syntaxes are also added atop of the method syntax (and thus works for normal methods as well…):

  1. path – recv.path::to::fun(args..)
  2. trait – recv.<Type as Trait>(args..).

We then have the following legal call syntaxes:

// Function syntax:
fun(recv, args..)
Type::fun(recv, args..)
<Type as Trait>::fun(recv, args..) // UFCS

// Method syntax:
recv.fun(args..)
recv.Type::fun(args..)
recv.<Type as Trait>::fun(args..) // UMCS

All of inherent, trait, and free functions can now be called using function syntax and method syntax.

This change requires zero intervention in user code and will just start working for all existing Rust code.

We then have macros mac!(recv, args..) and recv.mac!(args..) per Josh’s proposal.

3 Likes