# Macros as function chain

**URL:** <https://internals.rust-lang.org/t/macros-as-function-chain/11025>\
**Category:** Uncategorized\
**Created:** [September 30, 2019, 2:00pm UTC](https://internals.rust-lang.org/t/macros-as-function-chain/11025 "2019-09-30T14:00:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![storyfeet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/storyfeet/32/4461_2.png) [@storyfeet](https://internals.rust-lang.org/u/storyfeet)\
**Post date:** [September 30, 2019, 2:00pm UTC](https://internals.rust-lang.org/t/macros-as-function-chain/11025/1 "2019-09-30T14:00:25Z")

</div>

So I'm working on a macro, with a builder pattern. and I'd really like to be able to erite something like.

```rust
Myvar.my_macro!(...).another_macro!(...).finish();

```

Is this a thing? Does it already exist in some way?

---

<div class="post-metadata">

**Author:** ![Nokel81](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nokel81/32/3966_2.png) [@Nokel81](https://internals.rust-lang.org/u/Nokel81)\
**Post date:** [September 30, 2019, 2:08pm UTC](https://internals.rust-lang.org/t/macros-as-function-chain/11025/2 "2019-09-30T14:08:50Z")

</div>

It is not something that currently exists. And I think that there has been at least one RFC trying to define how this might work.

However, if I remember correctly from the text `a.b!(...)` would have (initially) been just short hand for `b!(a, ...)`

---

<div class="post-metadata">

**Author:** ![storyfeet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/storyfeet/32/4461_2.png) [@storyfeet](https://internals.rust-lang.org/u/storyfeet)\
**Post date:** [September 30, 2019, 3:32pm UTC](https://internals.rust-lang.org/t/macros-as-function-chain/11025/3 "2019-09-30T15:32:35Z")

</div>

Oddly, I'm actually not after the macro operating on "a" at all. I just want it to work in that place, and be replaced by a function.

Thankyou though, I think you have helped me solve my current problem.

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [October 1, 2019, 2:53am UTC](https://internals.rust-lang.org/t/macros-as-function-chain/11025/4 "2019-10-01T02:53:44Z")

</div>

> [@Nokel81](#):
>
> And I think that there has been at least one RFC trying to define how this might work.

> <https://github.com/rust-lang/rfcs/pull/2442>
>
> This RFC introduces simple postfix macros, of the form \`expr.ident!()\`,
> to make… macro invocations more readable and maintainable in
> left-to-right method chains.
> 
> In particular, this proposal will make it possible to write chains like
> \`computation().macro!().method().another\_macro!()\`, potentially with \`?\`
> interspersed as well; these read conveniently from left to right rather
> than alternating between the right and left sides of the expression.
> 
> I believe this proposal will allow more in-depth experimentation in the
> crate ecosystem with features that would otherwise require compiler
> and language changes, such as introducing new postfix control-flow
> mechanisms analogous to \`?\`.
> 
> Update: I've rewritten the desugaring to use the same autoref mechanism
> that closure capture now uses, so that \`some\_struct.field.mac!()\` works.
> I've also updated the specified behavior of \`stringify!\` to make postfix
> macros like \`.dbg!()\` more useful.
> 
> \[Rendered\](https://github.com/joshtriplett/rfcs/blob/simple-postfix-macros/text/2442-simple-postfix-macros.md)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [December 30, 2019, 3:04am UTC](https://internals.rust-lang.org/t/macros-as-function-chain/11025/5 "2019-12-30T03:04:56Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
