These are chat archives for rust-lang/rust

3rd
Dec 2016
Matanel Levi
@matanelevi
Dec 03 2016 10:02
Hey, someone can explain how macros works in Rust? I mean, when the expansion happens?
Is it find & replace like C? Just that it is hygienic?
David Harvey-Macaulay
@alteous
Dec 03 2016 12:34
Matanel Levi
@matanelevi
Dec 03 2016 12:35
@Alteous thanks, but It's not answering my question..
David Harvey-Macaulay
@alteous
Dec 03 2016 12:42
@matanelevi The expansion happens at compile time, and no, it is not a textual substitution. As for hygiene, see the following: https://doc.rust-lang.org/book/macros.html#hygiene.
Matanel Levi
@matanelevi
Dec 03 2016 13:10
@Alteous do you where it happens? the compiler substitutes the text in memory?
@alexcrichton ^ ?
Pavel Meledin
@btbvoy
Dec 03 2016 15:40
@retep998 Sorry for a bit deplayed response. I found that here: https://users.rust-lang.org/t/problems-building-and-linking-to-dlls/4943
funny that it looks like even you mentioned that “Right now DLLs produced by Rust aren't really designed to be simple DLLs…"
Peter Atashian
@retep998
Dec 03 2016 15:41
@btbvoy And then in my next post I mentioned an RFC which would fix that whole situation. Since then that RFC has been accepted, implemented, and stabilized
@btbvoy So you can very easily create DLLs in Rust for consumption by other languages with minimal bloat
Pavel Meledin
@btbvoy
Dec 03 2016 15:42
I was interested in opposite :-) do use existing DLL in my Rust app
@retep998 for some reason I really missed all the following your messages in that thread. Thanks for highighting that situation on that thread already improved and implemented :-D
Peter Atashian
@retep998
Dec 03 2016 15:45
@btbvoy Oh, if you want to use an existing DLL, then that post is rather irrelevant. In that as long as you have an import library it is quite easy and works really well.
Pavel Meledin
@btbvoy
Dec 03 2016 15:47
that’s awesome :-) thanks
Dave Hylands
@dhylands
Dec 03 2016 18:56
@matanelevi The macro expansion occurs early in the compilation phase. I think of sort of like a pre-processor even though it's not as simple as that. You can use something like the following to see what the expanded macro looks like: rustc -Z unstable-options --pretty=expanded test.rs
Matanel Levi
@matanelevi
Dec 03 2016 21:09
@dhylands thanks! My question is more like how the macros system is implemented
Dave Hylands
@dhylands
Dec 03 2016 22:57
@matanelevi My impression is that it's hooked into the parse tree, and it works by matching against the parse tree and then creating new parse tree elements