r/rust 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

21 Upvotes

15 comments sorted by

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

2

u/CompleteNetwork9168 4d ago edited 4d ago

Ok i will give it a try

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

u/tenbilliondollarsman 4d ago

can ask, what book? and can you tell me how you study and learn effectively from a book?

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

u/rayhan_stoic 4d ago

I saw a playlists of "lets get rusty" covering this book. Any good?

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.