0

I like that Rust comes with a lot of macros which moves computation to compile-time instead of repeatably to run-time.

print! and all its variants using format_args! See source code are great examples.

Unfortunately, in the source code you see the comment /* compiler built-in */ instead of a implementation direct in the source file.

Does Rust have the capability to let the user write such complex logic as a macro as well? If so, how can I do so?

1 Answer 1

1

Complex macros are usually implemented as procedural macros, which you can learn more about in The Rust Programming Language or in The Rust Reference books.

You can also achieve very complex things with the so called declarative macros, look at the excellent The Little Book of Rust Macros.

There are several talks about these on YouTube, but you may find the following in particular very interesting, which was given at the RustConf 2018, My Little Procedural Macro by Chris Wong:

youtube

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.