Ace Rust Macros ♠️ the declarative kind

  Рет қаралды 37,842

Code to the Moon

Code to the Moon

Күн бұрын

A fast and concise but gentle introduction to writing declarative macros in Rust. The code from this video can be found here github.com/Me163/youtube/tree...
-
Stuff I use to make these videos - I absolutely love all of these products. Using these links is an easy way to support the channel, thank you so much if you do so!!!
Camera: Canon EOS R5 amzn.to/3CCrxzl
Monitor: Dell U4914DW 49in amzn.to/3MJV1jx
Lens: Sigma 24mm f/1.4 DG HSM Art for Canon EF amzn.to/3hZ10mz
SSD for Video Editing: VectoTech Rapid 8TB amzn.to/3hXz9TM
Microphone: Rode NT1-A amzn.to/3vWM4gL
Microphone Interface: Focusrite Clarett+ 2Pre amzn.to/3J5dy7S
Tripod: JOBY GorillaPod 5K amzn.to/3JaPxMA
Keyboard: Redragon Mechanical Gaming Keyboard amzn.to/3I1A7ZD
Mouse: Razer DeathAdder amzn.to/3J9fYCf
Computer: 2021 Macbook Pro amzn.to/3J7FXtW
Caffeine: High Brew Cold Brew Coffee amzn.to/3hXyx0q
More Caffeine: Monster Energy Juice, Pipeline Punch amzn.to/3Czmfox
Building A Second Brain book: amzn.to/3cIShWf

Пікірлер: 110
@ultrapoci
@ultrapoci Жыл бұрын
Assigning "Bob" to variable "a" and "Alice" to variable "b" is just evil
@ohturry5591
@ohturry5591 Жыл бұрын
Lol😂
@ohturry5591
@ohturry5591 Жыл бұрын
It’s an sql relationship 🤫
@codetothemoon
@codetothemoon Жыл бұрын
hah, in retrospect that was a poor choice 🙃
@ThanhNguyen-lk6ns
@ThanhNguyen-lk6ns Жыл бұрын
It's a quantum teleportation 🤣
@furo.v
@furo.v Жыл бұрын
I was going to comment the same thing lol
@robinmoussu
@robinmoussu Жыл бұрын
I definitively love your style. Clear, short, on-topic!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Robin!!
@perc-ai
@perc-ai Жыл бұрын
This is the best rust macro video on KZfaq! Looking forward to all your future videos your quickly brecoming an industry leader
@codetothemoon
@codetothemoon Жыл бұрын
wow thanks for the kind words! I really enjoy making them!
@AceofSpades5757
@AceofSpades5757 Жыл бұрын
That was a really good, light introduction into Rust's declarative macros. Thanks!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks AceofSpades! It's almost as if the title and thumbnail were speaking directly to you 🙃
@eduardopereira2431
@eduardopereira2431 Жыл бұрын
Your Rust content its been incredible useful! Thank you!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Eduardo, thanks for watching!
@Ma1ne2
@Ma1ne2 Жыл бұрын
Loving these Rust videos so much, great to follow along and learn something new :) Keep them coming!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Noxdor, glad you are finding them valuable! more to come!
@tryoasnafi4340
@tryoasnafi4340 Жыл бұрын
love your explanation style, simple, clear and well structured
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Tryo!
@BrandonCharlesHouser
@BrandonCharlesHouser 11 ай бұрын
In VS Code, if you hold alt and then press the up or down arrow it will move the line you are on or your entire selection up or down. It's great for reorganizing switch statements, if else ladders, and just re-organizing code.
@codetothemoon
@codetothemoon 11 ай бұрын
ahh didn't know about this, thank you!
@egorsozonov7425
@egorsozonov7425 3 ай бұрын
It’s not great, it’s terrible. Pressing Alt and arrows at the same time requires you to move your hand very far from the home row! Better editors like Neovim have saner hotkeys as well as a way to reassign them arbitrarily
@luccao173
@luccao173 5 ай бұрын
I have to say, you really got the best Rust content. exactly the right tempo and right hints
@codetothemoon
@codetothemoon 5 ай бұрын
thanks so much!
@learntry9074
@learntry9074 Жыл бұрын
Each video by you is to the point, and really it has helped me a lot. E.g, the video on 'result', I knew Result enum, but after watching it I learned the use case for map_err. Thank you
@Akshay-be3qx
@Akshay-be3qx Жыл бұрын
Really cool way to explain. Thanks for taking time to make awesome videos.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Akshay!
@sparky173j
@sparky173j Жыл бұрын
Thankyou for this and all your other videos. I usually prefer learning these things from video demos over documentation. I've been procrastinating adding macros to my project. I'll probably mostly be using derive macros, but I think declarative macros will be a good place to start.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching tev. I really enjoy making them, especially when I get comments like this! Declarative macros can be a great place to start (though you don't have to). Will probably be making a custom derive video at some point...
@jeffg4686
@jeffg4686 Жыл бұрын
Found an interesting syntax today, which is tuple pattern matching, where all elements of the tuple value can become 'wildcard' matches / variables'.
@codetothemoon
@codetothemoon Жыл бұрын
I find this feature super handy, I think it's called "destructuring"!
@jeffg4686
@jeffg4686 Жыл бұрын
@@codetothemoon - yeah, it's destructuring, but never seen it before in this context (matching).
@perc-ai
@perc-ai Жыл бұрын
Hey there’s a new wave of rust developers especially after all the news that rust is changing everything… would love to see more videos from you
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Zah, more are on the way!
@ErikSchierboom
@ErikSchierboom Жыл бұрын
Lovely video! Love your pacing
@HyperFocusMarshmallow
@HyperFocusMarshmallow Жыл бұрын
Great introduction!!! It would be cool if you did one or a few follow ups of more advanced macros.
@pup4301
@pup4301 Жыл бұрын
Hey remember you can use the rust language reference to help under stand the token syntax of a macro!
@codetothemoon
@codetothemoon Жыл бұрын
Agree, it's a great resource!
@tonhom260
@tonhom260 9 ай бұрын
Love the way you teach us ,thank❤❤
@tuanlam999
@tuanlam999 Жыл бұрын
Great concise content. Rust to the moon 🙂
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Tuan! 🌙
@aksakalaradhita
@aksakalaradhita 9 ай бұрын
Man, you should have "in-depth rust" series
@codetothemoon
@codetothemoon 9 ай бұрын
would love to make such a thing!
@africknchickn_YT
@africknchickn_YT Жыл бұрын
if you do a similar walkthrough for proc macros, I *will* subscribe. In my experience, building a custom derive is a more common use case that I wish I had the time to learn in detail how to do, as opposed to defining and parsing a new DSL. So (if you're taking votes...) my vote would be for doing a recursive derive of structs and enums! If not, then no worries :) I'll still be around. Cheers dude!
@codetothemoon
@codetothemoon Жыл бұрын
Nice, I've been thinking a lot about a proc macro video. I've found it incredibly challenging to explain those concepts in a concise and digestable way - I think it can be done though! Thanks for watching!
@edgeeffect
@edgeeffect Жыл бұрын
​@@codetothemoon yeah! I've just been watching "9 rules for procedural macros" and my head is still swimming.
@advanceringnewholder
@advanceringnewholder 4 ай бұрын
​@@codetothemoonCheering on that. I hope you'll make that video and adding it to the knowledge pool of easy to digest video. Take your time
@ozkavoshdjalla
@ozkavoshdjalla Жыл бұрын
It was cool! Thanks
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Ozkavosh!
@zencephalon
@zencephalon Жыл бұрын
Great stuff!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Matthew!
@diwakargupta0
@diwakargupta0 Жыл бұрын
Awesome 🙌🙌
@codetothemoon
@codetothemoon Жыл бұрын
glad you found it valuable!
@pierreniberon1801
@pierreniberon1801 Жыл бұрын
Firstly, nice thumbnail, and then, nice video 👍
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Pierre!
@glebbash
@glebbash Жыл бұрын
Great stuff, sounds like macros are not that scary after all.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, indeed they are not! 😎
@glennmiller394
@glennmiller394 Жыл бұрын
Thanks!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Glenn!
@KyuuKun16
@KyuuKun16 Жыл бұрын
Your videos are AMAZING, would you consider making one delving deeper into concurrency?
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Jason, I'd love to do one on concurrency - it's already on the video idea list!
@AzureFlash
@AzureFlash Жыл бұрын
3:39 Trolling is a art
@codetothemoon
@codetothemoon Жыл бұрын
If I trolled it wasn't intentional! 🙃
@advanceringnewholder
@advanceringnewholder 4 ай бұрын
I wish you deep dive into procedural macro. I'm having a hard time wrapping my head around it.
@codetothemoon
@codetothemoon 3 ай бұрын
yeah i'd love to do this. i actually started writing a video about it awhile back but found it really difficult to present it in a clear way in the KZfaq video format
@alurma
@alurma Жыл бұрын
ty
@codetothemoon
@codetothemoon Жыл бұрын
you're welcome thanks for watching!
@tsalVlog
@tsalVlog 10 ай бұрын
we call it the mustache brace around here.
@codetothemoon
@codetothemoon 10 ай бұрын
nice! sounds far better than "curly braces"
@kennethbeal
@kennethbeal Жыл бұрын
"Aces!" - 16 Candles
@codetothemoon
@codetothemoon Жыл бұрын
Hah, I had to look this up!
@grindarius661
@grindarius661 Жыл бұрын
What kind of theme are you using? It is so cool and I wanted to know the name of it.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, it's Sonokai!
@arnimlost
@arnimlost Жыл бұрын
@@codetothemoon what font are you using?
@Daveiac
@Daveiac Жыл бұрын
Is there a way to specify the types of elements to the set? Like what if you were to do set!(1,"2",'3'), would it compile?
@ianakotey
@ianakotey Жыл бұрын
Nah, compiler would infer their types are different and reject
@codetothemoon
@codetothemoon Жыл бұрын
yeah like Ian mentions, the HashSet itself has to be of a specific type so this wouldn't compile - this isn't related to the macro itself, it would still happen if you tried to do that directly with HashSet::from
@jaromor8808
@jaromor8808 Жыл бұрын
what's up with that extra/last comma in the dbg! output?
@narayanbhat3279
@narayanbhat3279 Жыл бұрын
shouldn't you first create an empty hashset and then push each of the elements into the set?
@codetothemoon
@codetothemoon Жыл бұрын
That would work too. I'm honestly not sure which approach is more efficient.
@van3ll0pe
@van3ll0pe Жыл бұрын
C > rust I love c
@codetothemoon
@codetothemoon Жыл бұрын
What do you like most about C that Rust falls short on? What issues do you think C has that could be addressed in a future language?
@not_ever
@not_ever Жыл бұрын
@@codetothemoon Rust doesn't segfault enough. A real language segfaults at least three times before breakfast.
@legends_assemble4938
@legends_assemble4938 Жыл бұрын
Can u create a video on getting started with procedural macros.
@codetothemoon
@codetothemoon Жыл бұрын
I'd love to do that, and I actually started writing a script on at least one occasion, but I've found them to be incredibly challenging to explain in a simple way. I'll come back to it at some point 😎
@legends_assemble4938
@legends_assemble4938 Жыл бұрын
@@codetothemoon Thanks for considering my request 💛💛
@artursradionovs9543
@artursradionovs9543 Жыл бұрын
Does anyone know how to implement Stripe and JWT in rust for e-commerce
@codetothemoon
@codetothemoon Жыл бұрын
I second this. I've been mulling a Stripe video for some time, definitely a huge area of interest. For JWT / OAuth in Rust I actually did a video on that several months ago
@artursradionovs9543
@artursradionovs9543 Жыл бұрын
@@codetothemoon no official docs available. I love Rust a lot, but it takes a lot of time as a beginner to pick this up. My goal is to develop a small Android Native App with Actix as a backend framework, but note sure if I will succeed. Rust really is harder than Java, Python or JS.
@ambuj.k
@ambuj.k Жыл бұрын
What is your vscode theme in this video?
@codetothemoon
@codetothemoon Жыл бұрын
Sonokai
@tactics40
@tactics40 Жыл бұрын
nit: println takes a string literal, not a slice. One of the hallmarks of a macro is that it can distinguish the two whereas functions can't.
@codetothemoon
@codetothemoon Жыл бұрын
Ahh good point I was sort of using those terms interchangeably, but like you say in the world of macros they are different!
@eddex.
@eddex. Жыл бұрын
Why did the "thing = 5" variable match the "a arm"? And how can it match "a" when there's no variable called "a"?
@theaiguy_
@theaiguy_ 7 ай бұрын
That is because a can be anything, 5 included, so it matches.
@theaiguy_
@theaiguy_ 7 ай бұрын
Usually the general case is named "_", but really can be anything
@kavehtehrani
@kavehtehrani Ай бұрын
@@theaiguy_ thank you kind stranger!
@Polynuttery
@Polynuttery 4 ай бұрын
What did you mean that “a” matches on 5 ?
@codeplay4947
@codeplay4947 Жыл бұрын
What is your color theme
@codetothemoon
@codetothemoon Жыл бұрын
Sonokai
@codeplay4947
@codeplay4947 Жыл бұрын
@@codetothemoon Do you mean Monokai...I couldn't find Sonokai
@Elduque40
@Elduque40 Жыл бұрын
Do you have Rust for beginners?
@codetothemoon
@codetothemoon Жыл бұрын
Check out "Rust Demystified"! It goes straight to the heart of what makes Rust different from other languages
@phenanrithe
@phenanrithe Жыл бұрын
The best I've read is this book: Programming Rust by Jason Orendorff, Jim Blandy, and Leonora F .S. Tindall, O'Reilly. It covers the last 2021 edition, is superbly written and covers all the topics by explaining everything with a good learning curve. I've heard good things about The Rust Programming Language by Steve Klabnik and Carol Nichols, no starch press, but it's outdated (a new edition should be available later next year).
@banocean
@banocean 5 ай бұрын
Tbh your videos now are kinda let's do thing I can read in the docs/rust book :/
@codetothemoon
@codetothemoon 5 ай бұрын
thanks for the feedback. I only make videos on topics that are covered in the Rust book if I think i can offer a different approach and explanation that makes it easier to understand, which was the case for this video. Another example would be the one on interior mutability. Maybe I missed the mark on this one!
@marcelo55869
@marcelo55869 Жыл бұрын
𝓑𝓛𝓐𝓩𝓘𝓝𝓛𝓨 𝓕𝓐𝓢𝓣
Is Rust the New King of Data Science?
15:38
Code to the Moon
Рет қаралды 132 М.
rust macros are magic
14:02
Tantan
Рет қаралды 44 М.
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 35 МЛН
ПООСТЕРЕГИСЬ🙊🙊🙊
00:39
Chapitosiki
Рет қаралды 68 МЛН
Rust Powered Polymorphism ⚡️ With Traits
9:55
Code to the Moon
Рет қаралды 90 М.
Rust Interior Mutability - Sneaking By The Borrow Checker
16:02
Code to the Moon
Рет қаралды 64 М.
8 deadly mistakes beginner Rust developers make
14:14
Let's Get Rusty
Рет қаралды 156 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 135 М.
Constructors Are Broken
18:16
Logan Smith
Рет қаралды 100 М.
The Uiua Programming Language Caught Me By Surprise
12:24
Code to the Moon
Рет қаралды 49 М.
Mocking Rust 🤪 and Testing 🧪
11:58
Code to the Moon
Рет қаралды 36 М.
Rust's Witchcraft
9:18
No Boilerplate
Рет қаралды 172 М.
Speed up your Rust code with Rayon
6:50
Let's Get Rusty
Рет қаралды 45 М.
Rust: When C Code Isn't Enough
8:26
CodeAhead
Рет қаралды 152 М.
Bluetooth Desert Eagle
0:27
ts blur
Рет қаралды 7 МЛН
Дени против умной колонки😁
0:40
Deni & Mani
Рет қаралды 12 МЛН
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 17 МЛН
Apple watch hidden camera
0:34
_vector_
Рет қаралды 61 МЛН
WWDC 2024 Recap: Is Apple Intelligence Legit?
18:23
Marques Brownlee
Рет қаралды 5 МЛН