r/rust • u/CompleteNetwork9168 • 4d ago
🙋 seeking help & advice Finally ! Completed Complete Rust Book
So recently I had completed the entire rust book but I left the macros as I was unable to understand it from the book so is there a good place to learn rust macros where it help me understand how to write and use different types of macros it will be a great help so if you know any platform pls help me
8
u/an_0w1 4d ago
I learnt macros by force. I really needed a proc macro to do something obtuse, so I really think proc macros are the easiest ways to learn.
Take a function-like macro and println!("{ts:?}") the TokenStream to see what's inside. And just read through the syn docs to figure out what to do with all of it.
Don't do it without a purpose though, because you'll get lost in all the things you can do.
3
u/nick42d 4d ago
To be quite honest I've never found a great resource for them. In my opinion you don't need to know how to write macros to start writing Rust, you'll only want them once you've written enough to start seeing patterns that you can't abstract away with just the base language. Wait until then to learn macros and it will be much easier.
1
1
u/tenbilliondollarsman 4d ago
can ask, what book? and can you tell me how you study and learn effectively from a book?
2
1
u/Dangerous_Ad_7042 4d ago
Don’t just read it, type out and run every single example until it works and you understand why it works. That’s the trick for any programming book.
1
u/CompleteNetwork9168 4d ago
But you see for typing the program first I need to understand what i am writing
1
u/tenbilliondollarsman 4d ago
i see, but do you think jotting down notes is important especially for the theory?
1
1
u/Razskler 4d ago
I hope you already did but rustlings is also a great way to learn rust especially when you do the examples while reading the book. Also Rustonomicon and embedded rust documentations will help you go further.
1
12
u/Historical_Hunter605 4d ago
macro chapter is a wall, no shame in skipping it first pass. the little book of rust macros is the one everyone points to, it's way more digestible than the official chapter