Rust's Witchcraft

  Рет қаралды 170,821

No Boilerplate

No Boilerplate

Жыл бұрын

You and I would not be here today if it weren't for my favourite feature of rust, and indeed of any language: Macros.
I've mentioned them in the past, but in today's video I'm explain why they're SO POWERFUL.
❤️ If you would like to support what I do, I have set up a patreon here: / noboilerplate - Thank you!
📄 All my videos are built in compile-checked markdown, transcript sourcecode available here github.com/0atman/noboilerplate this is also where you'll find links to everything mentioned.
🖊️ Corrections are in the pinned ERRATA comment.
🦀 Start your Rust journey here: doc.rust-lang.org/stable/book/
🙏🏻 CREDITS & PROMO
Thanks so much to Laund for helping me fix a critical error in this script!
My name is Tris Oaten and I produce fast, technical videos.
Follow me here / 0atman
Website for the show: noboilerplate.org
Come chat to me on my discord server: / discord
If you like sci-fi, I also produce a hopepunk podcast narrated by a little AI, videos written in Rust! www.lostterminal.com
If urban fantasy is more your thing, I also produce a podcast of wonderful modern folktales www.modemprometheus.com
👏🏻 Special thanks to my patreon sponsor:
- JC Andrever-Wright
And to all my patrons!

Пікірлер: 632
@NoBoilerplate
@NoBoilerplate Жыл бұрын
ERRATA 0:21- link should be github.com/0atman/noboilerplate 1:25 - "The whole language always available" actually means at runtime as well as compile time. So Rust does the latter, but does not have the former. Hmm. 6:27 - typo in title. Should be "Arbitrary compile time execution"
@CaptainOfDoom
@CaptainOfDoom Жыл бұрын
I panicked for a second there
@pedrobraz2809
@pedrobraz2809 Жыл бұрын
0:21 it's com/0atman not com:0atman
@RenderingUser
@RenderingUser Жыл бұрын
@@CaptainOfDoom must have left something unwrapped then.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@pedrobraz2809 well spotted! I muddled up git/http address obviouly, woops!
@precumming
@precumming Жыл бұрын
I was wondering if there was a new permissable link format
@billhurt3644
@billhurt3644 Жыл бұрын
The idea that you can write valid HTML in your Rust files, with syntax highlighting and full Rust style error checking is just 🤯. Love these videos.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Rust's incredible isn't it? Though the syntax highlighting is down to the editor, I found that most editors highlight it really well! And of course once the web frameworks (like yew.rs) become more mature, folks will write editor plugins that highlight the html really well, just as JSX has!
@warpspeedscp
@warpspeedscp Жыл бұрын
@@NoBoilerplate rsx for the win
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@warpspeedscp Really great standard here crates.io/crates/syn-rsx/reverse_dependencies
@warpspeedscp
@warpspeedscp Жыл бұрын
@@NoBoilerplate wow, i didn't realise people were already working on thos
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@warpspeedscp Yeah! The macro I demoed in the video uses syn-rsx behind the scenes, loads do!
@user-vn9ld2ce1s
@user-vn9ld2ce1s Жыл бұрын
It's time for my regular dose of Rust appreciation
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Likewise friend, thank you so much :-)
@eymenu7281
@eymenu7281 Жыл бұрын
Lol
@eboatwright_
@eboatwright_ Жыл бұрын
same
@drew-et1mm
@drew-et1mm Жыл бұрын
@@NoBoilerplate Thanks doc 👨‍⚕️
@emmavdev
@emmavdev Жыл бұрын
My Friend who doesnt like Rust that much went "Oh, its just Rust D sucking" when I sent her this channel lmao
@TobiasSN
@TobiasSN Жыл бұрын
I love macro_rules because macros do indeed rule
@NoBoilerplate
@NoBoilerplate Жыл бұрын
that = true
@raffimolero64
@raffimolero64 Жыл бұрын
Still watching declarative macros 2.0 though, stuff looks a lot cleaner, shinier, and more consistent with the module system.
@TobiasSN
@TobiasSN Жыл бұрын
@@raffimolero64 Yeah, declarative macros 2.0 looks so much better! Can't wait for it to be in stable
@daishes
@daishes 10 ай бұрын
I though i was the only one that read it as "MACRO RULES!" It always sounded like a joke to me
@hashtags_YT
@hashtags_YT 10 ай бұрын
@@daishes Half the time it's precisely that, other half it's like the fundamental rules of the universe.
@olafbaeyens8955
@olafbaeyens8955 Жыл бұрын
The most famous sentence in Rust is: "We can do so much more"
@NoBoilerplate
@NoBoilerplate Жыл бұрын
"Hold my beer"
@KohuGaly
@KohuGaly Жыл бұрын
and the most infamous sentence continues: "...once we resolve the 5-year-old soundness issues in this laundry list of systems"
@mannycalavera121
@mannycalavera121 Жыл бұрын
@@KohuGaly example?
@qwertyqwerty-jp8pr
@qwertyqwerty-jp8pr Жыл бұрын
@@mannycalavera121 there is quite a bit of soundness issues, but they don’t really affect real code
@mannycalavera121
@mannycalavera121 Жыл бұрын
@@qwertyqwerty-jp8pr give me an example
@Blayzeing
@Blayzeing 11 ай бұрын
It's nice to see someone talking about macros like this. I think a lot of "Rust influencer" types aren't really aware of exactly what it means? Coming from a C++ background, when I saw the section in the rust book about macros I _immediately_ told my friend (who's very much a rust evangelist) that they looked really powerful and I was impressed by them, but he just didn't care and then started going on about the borrow checker and how the compiler "does everything for you". Your videos are a breath of fresh air that honestly have done more to make me want to get into Rust than any of the endless proselytizing I find a lot of rust devs do.
@NoBoilerplate
@NoBoilerplate 11 ай бұрын
Right! As I say in a few of my earlier videos, as a python developer, I didn't care about memory safety at all - I never had to! It's a bad selling point when there are 10 other LIFE CHANGING features to talk about :-)
@Blayzeing
@Blayzeing 11 ай бұрын
@@NoBoilerplate Totally. Looking forward to watching more of your content! Again, just absolutely loving the no-nonsense, straight-forward and balanced approach you have to topics.
@snudget
@snudget 5 ай бұрын
When I realized that I can run shell commands at compile time and insert the output at comoile time into the source code, I knew that rust easily is the best language
@NoBoilerplate
@NoBoilerplate 5 ай бұрын
RIGHT
@jeffreyjdesir
@jeffreyjdesir Жыл бұрын
This video sent me over the edge: I'm adding Rust to my Exercism tracks now!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Fantastic! It's not the easiest language to learn, my biggest advice is to read the error message twice, it's usually got the answer! also: - The Rust Book - Rustlings - fasterthanli.me - the rest of my videos...! Do come chat on my discord over in #newbie-advice if you get stuck, GOOD LUCK!
@theherk
@theherk Жыл бұрын
@@NoBoilerplate Great recommendations. Love fasterthanlime; also Jon Gjengset.
@cotneit
@cotneit Жыл бұрын
@@NoBoilerplate Don't forget Jon Gjengset! Love his and fasterthanlime's content, it's quite in-depth yet easy to follow
@rumplstiltztinkerstein
@rumplstiltztinkerstein Жыл бұрын
The borrow checker, macros and how generics are implemented are the bumpiest parts of learning the language. Everything else is easier to understand in Rust than other languages. You will love it when your code compiles and there is almost no bugs at all in your system.
@olafbaeyens8955
@olafbaeyens8955 Жыл бұрын
After the obligatory headache in Rust it gets better :-)
@AceofSpades5757
@AceofSpades5757 Жыл бұрын
After a year of Rust, I'm thoroughly impressed with what people have done with macros. It's just incredible.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Yeah! And There's SO much more we could do!
@holmybeer
@holmybeer Жыл бұрын
Procedural macros really blew my mind. This is beyond what I've seen in any other programming language (perhaps lisp), and is SO USEFUL. Attribute macros and Derive macros save-me a lot of boilerplate and spaghetti code... Thank you Rust developers for this bless
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Such a great feature THAT NO-ONE TALKS ABOUT OMG!
@vitalyl1327
@vitalyl1327 Жыл бұрын
Lisp, Forth, Converge, Nemerle, Template Haskell, and a lot more.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@vitalyl1327 Yeah! Great feature that I don't see why couldn't be in every language. Though Template Haskell has it's detractors.
@micahrufsvold
@micahrufsvold Жыл бұрын
@@vitalyl1327 Julia too! I think Julia and Rust are kindred spirits.
@vitalyl1327
@vitalyl1327 Жыл бұрын
@@micahrufsvold yes! And Julia front-end is based on Scheme, which makes it pretty natural to extend.
@anderdrache8504
@anderdrache8504 Жыл бұрын
I used relatively complex macros for example to be able to declare rust structs and generate the OpenGL/Vulkan data automatically to upload them to the GPU, they are really amazing. If you write your own procedural macro, your errors probably won't be quite as nice (usually just highlighting the whole macro invocation) unless you add errors manually but for your own code that should already be enough. I have some problems with them but I think the Rust team is working on improving them and I can still recommend trying them out!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Absolutely, it's a developing area, as Macros usually are. But what a feature ALREADY!
@RenderingUser
@RenderingUser Жыл бұрын
7:55 I thought I just saw my own neovim setup right there and was shocked But then I remembered I got the tool recommendations from you XD
@NoBoilerplate
@NoBoilerplate Жыл бұрын
ha! AstroNvim *is* pretty great.
@RenderingUser
@RenderingUser Жыл бұрын
@@NoBoilerplate agreed One of the best neovim setups
@aditeya1024
@aditeya1024 Жыл бұрын
I made a vec3 object in rust and using macros really made implementing the operator traits really easy. Definitely worth learning!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's so cool! Did you publish on crates.io?
@aditeya1024
@aditeya1024 Жыл бұрын
@@NoBoilerplate While I could, i'm fairly certain there are better implementations out there. What I built is part of a ray tracer implementation which I learned to build from a tutorial. I found the macros on stack overflow when trying to find an elegant solution to the problem.
@sekoia2812
@sekoia2812 Жыл бұрын
@@aditeya1024 ohh, please link! I'm doing the exact same thing and my vec3 file is ~300 lines of `impl Add for Vec3` etc..
@ZKtheMAN
@ZKtheMAN Жыл бұрын
@@aditeya1024 Was the tutorial "Ray Tracing in One Weekend", by any chance?
@aditeya1024
@aditeya1024 Жыл бұрын
@@ZKtheMAN yes it was
@ericng8807
@ericng8807 Жыл бұрын
Just what I needed on a Friday morning
@RoamingAdhocrat
@RoamingAdhocrat Жыл бұрын
Captain, it's Wednesday
@casperes0912
@casperes0912 Жыл бұрын
This is the one. I've always thought "Yeah, Rust is fine, but other languages give me just as much of all the benefits". But this here. This converted me. Checking your HTML is valid and even running test SQL queries at compile time? Awesome
@NoBoilerplate
@NoBoilerplate Жыл бұрын
People LOVE to forget the innovations of lisp! Do start with the book, it's really well written and approachable! doc.rust-lang.org/stable/book/
@casperes0912
@casperes0912 Жыл бұрын
@@NoBoilerplate thanks. I never really looked much at Lisp. Too many parentheses to see the beauty beyond it. But made a few compilers and interpreters for fun so might take a jab at a Lisp one sometime too to get friendly with it. Rust documentation generally seems nice and good.
@lucky-segfault4219
@lucky-segfault4219 Жыл бұрын
Procedural macros are unreasonably powerful. I'm working on one which can validate a SQL-like statements used by SurrealDB against a schema. So far it will correct your clause ordering, inject variables with proper escaping, ensure fields exist when you query against a schemaful table, and parse the results into any serde compatible type. The possibilities are endless, and would be even more so if the tokeniser could parse backticks.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
It's SO powerful, right? I love it!
@billbennings8990
@billbennings8990 Жыл бұрын
You have my utmost respect for some of, if not *the* most ideal short, sharp rust lessons.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much Bill, that's so kind of you to say. I hope to write many many more!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
blazingly fast!
@FABESTAH
@FABESTAH Жыл бұрын
Wow, even though I do not yet understand everything perfectly, I can feel the energy with which you produce these videos, thank you so much! :D
@NoBoilerplate
@NoBoilerplate Жыл бұрын
My pleasure! Thank you for saying so :-)
@ericbwertz
@ericbwertz Жыл бұрын
Be careful -- that's how you were tricked into getting "vaccines" of extremely dubious value. Macros may or may not be the right code injection for you!
@CaptainOfDoom
@CaptainOfDoom Жыл бұрын
The most complex thing I did with macro_rules! was a macro I called "fluid" that (recursively) turned a series of statement-looking lines into a builder chain, including support for nested builders. The whole thing is only like 20 lines, but *relatively* parseable, if you're used to recursive code at least. I cannot possibly imagine doing that on a text replacement-based "macro" engine.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
omg like clojure's arrow macro? (->) I LOVE IT PLEASE TELL ME THE PACKAGE NAME (don't use urls, yt hates that)
@CaptainOfDoom
@CaptainOfDoom Жыл бұрын
@@NoBoilerplate I'll be honest, I never thought about publishing it (or anything, for that matter). I will try doing so over the weekend, and get back to you on that!
@xValerikx
@xValerikx Жыл бұрын
@@CaptainOfDoom Please post it here if/when you do publish! :)
@katech6020
@katech6020 Жыл бұрын
Don't forget to share it
@diadetediotedio6918
@diadetediotedio6918 Жыл бұрын
@@NoBoilerplate I do know the macro "pipeline" from my searches, you can do things like: let length = pipe!( "abcd" => [len] => (as u32) => times(2) => [to_string] ); // from their documentation I did not use it yet, but I saved as fav because it looks so cool
@btschaegg
@btschaegg Жыл бұрын
So the KZbin algorithm has been recommending me your videos now and then for a while now… But now I've literally had 30 seconds of brain lag where my mind *insisted* that I know your voice from somewhere else. When I started to listen to Lost Terminal out of curiosity, I'd never have thought it'd come with a free podcast of Seth nerding out about programming details :D. I'm sold. Thank you for both!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
oh amazing! I love it when the stars align for that! Hey, I have two other podcasts you might like, one that does exist and one that doesn't yet but you should keep an eye on: 1. Modem Prometheus, urban fantasy written by my friend Neil and performed by my friend Kate. I produce and write music (also I read the credits) If you love Buffy or anything Neil Gaiman has been involved in, you'll love this first episode: kzbin.info/www/bejne/lYSnn4iMfaZ2apY 2. /usr/stories podcast. Similar to Lost Terminal, hard scifi but set this time in the past. Season 1 in pre-production, probably will drop in a month or so twitter.com/usrstories Thank you!
@btschaegg
@btschaegg Жыл бұрын
@@NoBoilerplate Got it, thanks for the heads up! :)
@ducksies
@ducksies Жыл бұрын
FINALLY, after so many decades, other languages are beginning to look into what Lisp macros have to offer.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
EXACTLY. I'm excited by Rust because it takes most of the features I love from Lisp and Haskell and hides it inside C's clothing :-D
@kuhluhOG
@kuhluhOG 9 ай бұрын
@@NoBoilerplate Quite frankly, imo Macros (especially Macros as powerful as LISPs) are more of a downside than an upside when working together with a lot of people. Seriously, is it so hard to use the same code for runtime and compile time generation (oh, wait, it's not, Zig has done it).
@NoBoilerplate
@NoBoilerplate 9 ай бұрын
@@kuhluhOG You've missed the point: Rust macros have full access to the system - disk and network etc. SQLx can't be written in zig's comptime because it has no access to the system at compile time. You can write zig's comptime inside rust macros, but not the other way around. Proof: crates.io/crates/comptime BTW rust ALSO has what you want: doc.rust-lang.org/reference/const_eval.html
@kuhluhOG
@kuhluhOG 9 ай бұрын
@@NoBoilerplate About Rust's sqlx crate: I think you mean the query! macro to not be possible because everything else is in fact possible with Zig's comptime. Also, full network and disk access at compile time is not necessarily wanted by everyone (for example the C++ committee voted against giving std::embed because they thought of it as too insecure; yes, really...). But I don't think you get why I dislike Macro's that much. It's not about the power of network access or the like, it's that you can embed or even invent your own language inside of it and that it has essentially it's own rules compared the rest of the language (to a point where one can consider it it's own PL). While this may not be too bad for a project (you can straight up outlaw these kinds of things), you can't do that on an ecosystem level. This leads to ecosystem divergence on not a choice, but understandability level. Also, const_eval is quite limited compared to Zig's comptime
@NoBoilerplate
@NoBoilerplate 9 ай бұрын
@@kuhluhOG Rust isn't a theoretical language, it's been out for 16 years with macros. Your fears have not come true. Macros are FINE, honestly 🙂
@julienmarcuse9023
@julienmarcuse9023 Жыл бұрын
I always love seeing your Rust talks, I've been into the language for a while but they have really helped me appreciate all that makes Rust so excellent. I have absolutely loved macros myself, they're a complete game changer and I didn't know how much I needed them in other languages until I had them in Rust. In any other language I would bemoan the hefty syntax, but in Rust I never actually mind my code getting large, since I know that I will only ever have to write it once. Once and ONLY once, because I can use the type system to build such powerful abstractions, and where even that falls into monotony, macros pick up the slack by letting me compress repetitive syntax like implement blocks into a single line.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's right! But don't forget (I beg you) that proc macros can access the disk and network. What might you do with that power?
@philippecholet9484
@philippecholet9484 Жыл бұрын
@@NoBoilerplate In a proc macro, I did parse the library dependencies (reading "Cargo.toml") with the "cargo_toml" crate because my advent of code binary needs a solver library for each puzzle, list that evolves with time.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@philippecholet9484 so meta, I love it!
@Artentus
@Artentus Жыл бұрын
Procedural macros really allow you to do some black magic. I once wrote one that allows the user to turn very verbose parser combinator code into a concise DSL with infix operators.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
yaaaas did you publish?
@Artentus
@Artentus Жыл бұрын
I did, the crate is called langbox
@TheFreeSpiritKID
@TheFreeSpiritKID Жыл бұрын
wat?
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@Artentus Amazing! crates.io/crates/langbox
@Artentus
@Artentus Жыл бұрын
​@@NoBoilerplate thanks!
@RootsterAnon
@RootsterAnon Жыл бұрын
Yet another great video. I enjoyed every second. I just started to expand my knowledge about macro! and this is great to have in mind. 👏👏
@NoBoilerplate
@NoBoilerplate Жыл бұрын
thank you so much!
@wannabelikegzus
@wannabelikegzus Жыл бұрын
Okay, I only understood like 10% of that, but I'm stoked to learn more.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
It's a complex topic! Check out my other rust videos 😁
@Mesqa3o
@Mesqa3o Жыл бұрын
You are really good, the sound is so comfy that I can see the video and enjoy the information. Thanks for the great video
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much for saying :-) I have a lot of practice speaking because I am currently on season 11 of my hopepunk/scifi podcast, Lost Terminal. I'd love for your feedback on it! Episode 1 is here kzbin.info/www/bejne/pmTFdXhvoNitg8U
@wtcxdm
@wtcxdm Жыл бұрын
Thanks for the interesting video as always! Still halfway through the book but it’s really good to see so many new, fun things to learn.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Fantastic! You're gonna have a great time, and thanks for your support friend :-)
@RinLovesYou
@RinLovesYou Жыл бұрын
every time i miss hearing you talk about rust, you're right there! great video as always~
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much! I'm on a regular 2 week schedule now on fridays. (though Patrons get the video a day early!) Perhaps you'd like to hear me talk about science and tech through the lens of a fictional AI? That's what my podcast Lost Terminal is about! kzbin.info/www/bejne/pmTFdXhvoNitg8U
@Mikenight120
@Mikenight120 Жыл бұрын
I am here because ThePrimeagen allowed me to discover this channel and find curiosity in NeoVim and Rust hoping to enjoy this journey! Love the channel content!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much! Primeagen is such a nice chap, welcome!
@oh_suiiii
@oh_suiiii Жыл бұрын
“The dream of Scala is alive in Rust", I love it
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I am so sad that scala has deprecated xml literals - what a cool feature! Ah well, we have Rust now :-)
@averageyoutubeenjoyer5865
@averageyoutubeenjoyer5865 Жыл бұрын
Love your videos, seeing the potential of procedural macros I would love you see you go in deapth for that topic and explain the syntax and how they are used. Amazing video man, love your work
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you! I have noted that, and it looks like I will indeed do a part 2 in the future!
@yankee-in-london
@yankee-in-london Жыл бұрын
love your videos ... always smart and thoughtful ... keep on keeping on; you make a difference.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's so kind of you to say Ken, thank you, I will! :-)
@AgentXegy
@AgentXegy Жыл бұрын
I want to point out that C++ got constexpr and consteval, they are compile time expression and can be made into function that run in compile time.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Can't do side-effects though, right? Can they access the network at compile time?
@somenameidk5278
@somenameidk5278 7 ай бұрын
@@NoBoilerplate i've seen a demo that printed ASCII art at compile time at different scales based on a size parameter, so some side effects can be done
@NoBoilerplate
@NoBoilerplate 7 ай бұрын
@@somenameidk5278 I'm delighted to inform you that this sounds like a bug in the compiler's handling of constexpr "neither std::cout
@cyrilemeka6987
@cyrilemeka6987 4 ай бұрын
​@@NoBoilerplateamazing
@malteesch
@malteesch Жыл бұрын
This has grown to be my favorite channel on yt. Nice vid as always!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you! You're too kind!
@Saeid-Za
@Saeid-Za Жыл бұрын
You really make my day by uploading a new video, keep up the excellent work ❤️
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's so kind of you, thank you!
@jongeduard
@jongeduard Жыл бұрын
Thanks. Great addition to what I have read in chapter 19.5 of the The Rust Programming Language book. The book goes a bit more into detail (and the Reference and other docs probably even a lot more, but I am not there yet), but this video has greater examples with HTML and SQL. We keep learning. :)
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much! Yes, The Book is wonderful, as is Rust By Example and Rustlings. I imagine Amos over at @fasterthanlime (fasterthanli.me) will one day write the definitive article on Macros and then we'll all be enlitened!
@somebody_on_the_internetz
@somebody_on_the_internetz Жыл бұрын
I really like the way you narrate this video. This really motivates me to finally have a deeper look at how to write Marcos in rust. Aside have you ever had a look at type providers in rusts cousin F#? There is a SQL type provider that checks your query definitions at design and compile time. Also exists for CSV, XML and others. If Microsoft put a little more love into it it would blow C# out of the water.
@jakubbartczuk3956
@jakubbartczuk3956 Жыл бұрын
Man everything you made that KZbin suggests is gold, love your content
@NoBoilerplate
@NoBoilerplate Жыл бұрын
My pleasure! Do check my other videos, they're in the same style, and I do interesting non-rust videos too!
@cherdak_turista
@cherdak_turista Жыл бұрын
Amazing! Thank you. Would be cool to to see DSL with Rust macro video from you as well)
@NoBoilerplate
@NoBoilerplate Жыл бұрын
noted, thank you!
@ZacksArtz
@ZacksArtz Жыл бұрын
You convinced me to try using Rust (I was previously an avid golang user) and I'm loving it
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Go is great! You're gonna have a great time with Rust, it punches through both go's ceiling and floor to be lower-level and higher level than it. To get the async ergonomics you're used to with go, learn tokio, it's the de-facto standard. Do watch my videos and read all of fasterthanli.me and The Rust Book! Have fun!
@andredasilva6807
@andredasilva6807 Жыл бұрын
as always an amazing new rust video. macros are so good.. i need to get more into it.
@redcrafterlppa303
@redcrafterlppa303 Жыл бұрын
I wrote a macro library that mangels the correct jni name based on given parameter types and package info. It also encloses your code so you can return a result and it will throw a java exception if it's an error.
@invitapriore
@invitapriore Жыл бұрын
Hey, I just want to thank you for these videos. This channel is one of the few I've found that is targeted to experienced practitioners, presented even-handedly, and isn't just horrendously off-putting from an aesthetic standpoint, so I hope you'll keep going for a long time. Re proc macros, I'm still a low-intermediate Rust user and hadn't previously encountered anything like Yew's html macro in the wild, and so I think I assumed when I saw that they consume TokenStreams that they necessarily took in basically Rust-adjacent syntactic forms. I'm glad to see that they're much more powerful than that! They do make me long for an intermediate point on the simplicity vs. power scale, since Rust has solutions for both extremes but nothing right in the middle, which is how I would characterize Common Lisp's or Clojure's "defmacro" since these allow you to transform and generate syntax with simple list operations and don't require all the machinery of parsing (CL of course has reader macros too, which are basically equivalent to proc macros in their flexibility to define new syntax entirely). Of course that's a consequence of Lisp syntax being composed of lists already and so there's likely no possible analog in Rust, I just miss that particular affordance. Still, it's amazing to have a feature this expressive in a language that also permits such explicit control of details like memory layout. It's truly an excellent environment to work in.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much for saying, I really appreciate it. I am indeed targeting just those sort of users, and I aim to not just continue, but ramp up this year, with some tasteful adverts, I might even be able to go full-time youtube! Check out macro_rules! for a simple solution that does the parsing for you, lisp style!
@Turalcar
@Turalcar Жыл бұрын
I avoid macros whenever I can. The most complicated one I had to write is to verify that an array is sorted. And I will replace it with a const function whenever that becomes possible
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I daresay we will get const functions, just as we got macro_rules! compile-time matchers, anyone can write this feature for us today, within a macro!
@syudagye2837
@syudagye2837 Жыл бұрын
One of the best example of procedural macro i know, is the derive_xrb! macro from the WIP xrb crate. It includes custom syntax to implement the types needed for X11, as well as serialization and deserialization. This is awesome work from Antikyth !!!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Fantastic!
@_fudgepop01
@_fudgepop01 Жыл бұрын
YEAH OK FINE. I GET IT. YOUVE CONVINCED ME. Next WASM experiment I try - or reverse engineering/modding experiment - will almost certainly be in Rust because your way of breaking down the features in a digestible manner and into layman’s terms is absolutely bloody brilliant. Thank you, or heck you - time will tell (though I’m quite sure it’ll be the former)
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I'm so pleased! You'll have such a great time, make sure you watch the rest of my rust series, starting with this one on wasm: kzbin.info/www/bejne/hmWvfpmhe7GFqas
@BenjaminWheeler0510
@BenjaminWheeler0510 Жыл бұрын
Babe wake up new rust cult video dropped
@NoBoilerplate
@NoBoilerplate Жыл бұрын
All are welcome in the cargo cult!
@theninjascientist689
@theninjascientist689 Жыл бұрын
This is just what I needed after a long day of fixing issues in a java codebase caused by over-reliance on boilerplate.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
All those extra bloated features in java, all they need was proper macros in 1996!
@RetoonHD
@RetoonHD Жыл бұрын
yeah the sqlx query macro is actually insanely nice. It's everything i want from an ORM without any of the things i hate about ORMs
@NoBoilerplate
@NoBoilerplate Жыл бұрын
It's fun to think what postgres/whatever features sqlx supports. All of them.
@nahiyanalamgir7056
@nahiyanalamgir7056 8 ай бұрын
This is mind blowing!
@gdjhd1700
@gdjhd1700 Жыл бұрын
I currently don't have the time or motivation jet to lern Rust and have a hard time to understand the syntax as a java user (because of school). So I like your funny words, magic man.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I wrote just the video for you, Rust is easy! kzbin.info/www/bejne/eXvXp6GbpbKJd7c
@stracker494
@stracker494 Жыл бұрын
The rust macro system is wonderful, but it does have its caveats. Declarative macros have some limitations, since they always have to output some standalone valid code, which makes them hard to combine. You end up having to use the weird TT muncher pattern, which is pretty impractical and hard to read. Procedural macros are also limited by the complete lack of context to their input. If you want to make a procedural macros that feels idiomatic to rust, you'll quickly feel the lack of typing or general location of the call.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Oh yeah, I have so much respect for those who write macros. Even in lisp, macro's natural habitat, they're weird. Worth it though!
@thedeathstar420
@thedeathstar420 3 ай бұрын
I primarily code in Julia and it has this feature too. Really cool way of programming
@codedifferent
@codedifferent Жыл бұрын
I started learning Rust this past December and didn't really get how macros worked (aside from the simple text-substitution ones). The SQL example one helped me out a lot. Now I want to try making macros that execute at compile time and maybe integrate them into a project I'm working on.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Wonderful! Yes they're tricky to understand at first. I only understood their importance due to my lisp background. Good luck!
@michaelschnell5633
@michaelschnell5633 Жыл бұрын
Thanks a lot for covering this advanced issue ! I am impressed about what Rust macros can do !! E..g. executing code at design time e.g.with the database crate. I suppose it is possible to write code that is to be executed as well at design time as in the compiled program, when executed. But this is not a completely unparalleled feature. *Delphi* - in it's combination of language / compiler, library, and IDE - also features database access at compile time to try out and configure the communication with a database server. Moreover Delphi uses the same paradigm for it's "WYSIWYG" GUI designer. Here the code at compile time displays the GUI under constructions (allowing to use the mouse for editing the design) and writes a file (similar to jason) with the construction and functionality rules. As runtime the (essentially) same code reads that file (in fact embedded in the executable as a resource) and displays the GUI to be used by the business logic. I do hope that something similar once will be provided by an appropriate Rust crate (of course based on Macros), e.g. based on egui / OpenGL. Same will allow to create projects that can be compiled for multiple platforms including Browser / webassembly. Thanks for listening
@NoBoilerplate
@NoBoilerplate Жыл бұрын
The great thing with HTML, as a universal interface language, there are MANY visual designers that you can build your UI in, then just template them into your server code with (say) rocket.rs.
@michaelschnell5633
@michaelschnell5633 Жыл бұрын
@@NoBoilerplate Can you comment on " I suppose it is possible to write code that is to be executed as well at design time as in the compiled program, when executed"
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@michaelschnell5633 What does "design time" mean? I'm Familiar with compile time and run time?
@michaelschnell5633
@michaelschnell5633 Жыл бұрын
​@@NoBoilerplate My dream always was a system that allows for a decent local GUI and and a bowser based GUI (i.e. local and remote GUI to choose from). With Rust this seems to be possible by Webasm and WebGL (e.g. vi egui) . But nowadays it might be appropriate to use html for this by implementing a browser in the desktop app. Now for design time a WISYWIG HTML editor might be implemented by a Rust Macro. I just don't yet see how to have the designer easily bind business logic functionality within the GUI design flow. But I am no expert on HTML stuff at all :) -Michael
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@michaelschnell5633 Ah! I see! I'd recommend trying out tauri.app and doing their tutorial, getting a simple app working, and taking it from there! Lots of videos on youtube can help you design html interfaces, it's really not too complicated, I promise 🙂
@tristanmisja
@tristanmisja Жыл бұрын
This video has made me decide to start using Rust.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Wonderful! Do check out my other videos, there's so much good stuff here! kzbin.info/www/bejne/n5fEfZ5rq5iKb5I
@legendrags
@legendrags 6 ай бұрын
I never thought rust would be so easy yet so complicated. Love it.
@NoBoilerplate
@NoBoilerplate 6 ай бұрын
It's terrific! Do check my high-level intro to Rust: kzbin.info/www/bejne/pYqTiaqDhLitp5Y Sorry to be picky (kind of my job!) but I think of Rust in the opposite terms: It's not easy, but it is simple.
@legendrags
@legendrags 6 ай бұрын
@@NoBoilerplate If I was able to understand it, then it is easy bro.
@Rudxain
@Rudxain Жыл бұрын
I've been procrastinating the learning of macros. My SV3G repo would seriously benefit from them! (I need to validate CSS colors and SVG strings at compile-time)
@NoBoilerplate
@NoBoilerplate Жыл бұрын
oh that would be perfect for a macro! Make sure you're always using nightly, and try this to help understand what is happening github.com/dtolnay/cargo-expand If you need help, post in #programming on my discord, loads of smart people live there! :-)
@Rudxain
@Rudxain Жыл бұрын
@@NoBoilerplate Thank you!
@thebaconbreadful
@thebaconbreadful Жыл бұрын
Hey! I really appreciate your videos and this one as well! Would you mind spelling abbreviations you use out on your presentation cards? I find myself googling some of them.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Thank you so much! This is a great idea, I will put in the markdown scripts links to the first usages of all abbreviations going forward! github.com/0atman/noboilerplate/
@thebaconbreadful
@thebaconbreadful Жыл бұрын
@@NoBoilerplate I can give that thank you right back! I really enjoy your videos and you being so open to feedback will improve on that even more.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@thebaconbreadful this is the way!
@formulaetor8686
@formulaetor8686 Жыл бұрын
Your voice is super soothing and distracts me from focusing on what you're explaining (can't blame you though lol). Jokes apart, nice and enjoyable content packed with information. Could you also please make videos on low level/unsafe rust too because there aren't many.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's so kind of you to say, thank you! I'm afraid it'll be a while till I do a deep-dive on unsafe and low-level, because I don't work with that level typically. I've talked about it in half of this video, and I'm very happy with the high-level description: kzbin.info/www/bejne/hqawiYqZZd2lgZI If you would like to hear my voice in a format where I'm TRYING to be soothing, I'd love to know what you think of my AI/hopepunk scifi podcast, Lost Terminal kzbin.info/www/bejne/pmTFdXhvoNitg8U
@formulaetor8686
@formulaetor8686 Жыл бұрын
@@NoBoilerplate Hello, I've just listened to the lost terminal podcast and I could relate to the satellite because I'm lonely too. Again, could just listen the whole podcast just for your soothing voice, but as for the podcast content, I personally didn't find it really engaging and entertaining 😅 (super sorry, but please don't feel bad and think that you're making bad content, its just my personal opinion and there are many viewers apart from me who love the podcast).
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@formulaetor8686 Quite alright! I produce and write the music for Modem Prometheus, maybe you'd like it instead? It's very VERY different kzbin.info/www/bejne/lYSnn4iMfaZ2apY&embeds_euri=https%3A%2F%2Fmodemprometheus.com%2F&feature=emb_title
@kaiiboraka
@kaiiboraka Жыл бұрын
I like your funny words, magic man. I was with you until about halfway through and then I had no idea what was happening, but it sure sounded impressive! I'm still kind of scared of rust, to be honest. Maybe I'll come around eventually lol
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Ha! Macros are so weird aren't they! Don't worry, you don't have to write a single one to write normal Rust. It's like writing C extensions for python/js/ruby etc, it's mostly wizards who do that for us! You sound like you need a relaxing video to watch after this one, I prescribe kzbin.info/www/bejne/eXvXp6GbpbKJd7c (let me know what you think!)
@lionbryce10101
@lionbryce10101 Жыл бұрын
I love watching Rust videos. That one snippet for bounded_impl had just enough syntax hell to dissuade me from wanting to learn it though
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Oh don't even worry about macros, they ALWAYS look nasty in whatever language you write! There's an old lisp saying "never do in a macro what could be done in a function". True in Rust too! Rust syntax is only as complex as it has to be, I promise. There's loads of great features that simply require more syntax to work. You must make your programming language as simple as possible, but no simpler. I'd love to know what you think of my video here kzbin.info/www/bejne/eXvXp6GbpbKJd7c
@lionbryce10101
@lionbryce10101 Жыл бұрын
@@NoBoilerplate I'd seen the video before, just watched it again. I'll never say the compiler isn't really handy since that's what everyone talks about with Rust and I'm sure you can get 90% of the way there with just the compiler messages. My main reasons for not learning it are: 1. I just don't have a use for any compiled languages at the moment (I use Lua to make addons for various games and Python to get data off of websites) and when I write code I want it to run immediately without waiting for compile time 2. When I do need to use a compiled language, memory safety is usually not on my mind because I'm not doing anything important or to scale 3. (Especially for Rust and C++) when I look at other people's code and see a ton of mumbo jumbo(&forThe,compiler) => {} it's a real turn off, not that most languages don't have their moments of that but c++ was really nasty to look at and Rust is just c++ with added rules, syntax, etc cool logo and nice idea though
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@lionbryce10101 Absolutely fair, lua's really great (I recently converted my nvim config from vimscript to lua and I'm so much happier! If you want to play in the following domains, Rust might be worth the price of entry: - webasm - bare-metal without using C - high-performance computing My take is Rust is EXTREMELY different to what I was used to: No inheritance, new syntax for lifetime annotations and borrows, and the compiler hates a lot of the standard normal patterns we've been using for decades. I know how you feel there! Back in 2020 I crashed out of learning Rust twice. First time due to multiple string types (Haskell's biggest mistake made again, I thought to myself) and second due to the lifetime syntax. At the time I had a great mentor who picked me up and helped me back on the path. Most people don't have this. This is why I made my Rust series. Yes Rust is very different from what you're used to. But that's the point. Anyway, you sound like you're in a good place, no rush to learn new stuff. Python made my career for 15 years, no harm in that at all. BTW do check out bevyengine.org/examples/ if you're interested in game dev, impressive stuff there. Certainly, people on my discord rave about it! Cheers!
@Aspiiire
@Aspiiire Жыл бұрын
Fantastic videos thanks :)
@NoBoilerplate
@NoBoilerplate Жыл бұрын
My pleasure!
@mechwarrior83
@mechwarrior83 Жыл бұрын
I would have settled for Rust style error checking alone but this takes it so much further. I cannot wait to see this language with a little pedigree behind it.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Don't wait my friend, Rust's already replaced C in the Linux kernel, in Discord, in CDNs around the world, and even some of NPM's backend services. It's achieved critical mass, and is ready! What are you waiting for, what's not good for you?
@anamewithnoface1330
@anamewithnoface1330 Жыл бұрын
I don't know why I like these videos so much, I have never written a single character of anything resembling code in my entire life.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
You're so kind! I wonder if you'd like a scifi story read by me, if that is the case? I'd love to know what you think of Lost Terminal kzbin.info/www/bejne/pmTFdXhvoNitg8U
@anamewithnoface1330
@anamewithnoface1330 Жыл бұрын
@@NoBoilerplate I watched the first three episodes. I'm very interested! I find it actually captivating to think about what an AI actually 'thinks' about. Though Seth is very personified for an AI, he is quite endearing. looks to me that I have something new to listen to on my drives to work! thanks for your great work and dedication to the story!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@anamewithnoface1330 I'm so pleased! I too love listening to podcasts while on long journeys - perfection! You can listen to LT on spotify, itunes or wherever you listen to music and audio - more handy than youtube when in the car! If you'd like to chat about LT (or indeed NB), come and say hi on my Discord server!
@joaosouza2678
@joaosouza2678 Жыл бұрын
Your channel is making me fall in love with Rust! Do you have any recommendations to land a job? Most of the positions I see requirer at least 3y of exp. Im currently freelancing Fronend and Web3 (Solidity and Js basically), but never worked in a company before. Looking forward to dev smart contracts in the NEAR Ecosystem, looks promissing.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
There's a small but growing market for Rust developers, all the big players are taking rust seriously, look at this list that contains Microsoft, Aws, github and others www.rust-lang.org/sponsors - find their job boards and apply to them all! Secondly, four of my videos were sponsored by companies actively recruiting for Rust devs, apply quick! Videos: - kzbin.info/www/bejne/gHrZfJqJrtunrqs - kzbin.info/www/bejne/hmWvfpmhe7GFqas - kzbin.info/www/bejne/r2KTm32OaJqmnqc - kzbin.info/www/bejne/qZO5qaRto7OnndE Good luck! I'll try to add more sponsors who are recruiting for Rust, and maybe even do a "how to" video in the future!
@tonhom260
@tonhom260 9 ай бұрын
just new to this rust, really love this concept !!!
@NoBoilerplate
@NoBoilerplate 9 ай бұрын
It's *amazing*, so much of what I like in one languages. Do check out this short playlist of my best Rust videos for more info kzbin.info/www/bejne/pYqTiaqDhLitp5Y
@tonhom260
@tonhom260 9 ай бұрын
i will surely thankyou dude@@NoBoilerplate
@0.Maiden
@0.Maiden Жыл бұрын
In the future I also want to learn about the rust, and I have a question, does the rust have "full oop features - four principles of oop" like c++, java? thanks p/s: sorry for my english, i used gg translate
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Perfect english! Rust is not an OOP language, it is BETTER than that. As you learn more about languages, you may discover alternatives to OOP that are just as good - we often think of OOP as the *only* way to program, but it's simply *one way* to program. If I'm reading this right, the 4 principles are abstraction, inheritance, encapsulation, and polymorphism. Rust has all of those, but in very different ways than Java and C. polymorphism is the most different in Rust. Rest assured, Rust has comprehensive techniques for building as large projects as you want. I would recommend reading The Book: doc.rust-lang.org/book/ Good luck, and please ask me more questions on my Discord if you need help :-) (links in the description)
@0.Maiden
@0.Maiden Жыл бұрын
@@NoBoilerplate thanks, what I am interested in is that rust has all 4 principles of oop, and surprisingly it still has those principles, about how to approach and implement them, I will research
@bradtechnologies
@bradtechnologies Жыл бұрын
I'm in awe!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Rust's pretty incredible! Do check out my other videos to get more excited about it :-)
@kira.herself
@kira.herself Жыл бұрын
I love every single video of yours ♥
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's so kind of you to say! I wonder if you've watched my little hopepunk/scifi show, Lost Terminal? kzbin.info/www/bejne/pmTFdXhvoNitg8U I'd love your thoughts on it!
@giftgod_jr
@giftgod_jr 2 ай бұрын
Just a quick question: is this a viable solution for building DSLs? I wonder that beacuse I'm trying to build a DSL for cards games and wanted to use rust for its performance
@redumptious2544
@redumptious2544 Жыл бұрын
Holy shit. I thought the feature interesting but failed to grasp it's real use (beyond i.e. a build system). But the sql blew me away. Awesome as always Tris.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Fantastic. I'm so pleased, this was just the sort of misunderstanding I was hoping to help with by making this video - Macros are great! XD
@MrAngeloniStephen
@MrAngeloniStephen Жыл бұрын
This is the one video that Really makes me want to get onboard. I love using SQL to generate SQL so this is Panacea. But boy do you speak fast ! Thanks for everything.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
My pleasure!
@PlonkapplePrequel
@PlonkapplePrequel 9 ай бұрын
So with the feature of embedding other language inside of rust, is there a way to type rust, but with the indent based syntax that python has without squiggly brackets?
@NoBoilerplate
@NoBoilerplate 9 ай бұрын
I bet there is (search crates.io) but let me defend curly brackets: I've written python professionally for 15 years. At the start, indentation scope is nice and easy. When you're at production-level, and you've got huge levels of indentation and debugging where the mistake is, you wish wish WISH you had curly braces XD This is how I think about Rust's more complex syntax: there's more detail, but it's there to help you. My video on this here: kzbin.info/www/bejne/aJm7f5dsrZ6mkNU
@jakob7116
@jakob7116 Жыл бұрын
In javascript land we have like different languages on top of js .svelte .vue .jsx which is a pain. But I've tried the yew html macro and it doesn't auto complete like writing -> and when I don't seem to get any intellisense inside the macro. Not if I go into an element to put for example the class attribute and not either in the rust code inside. Is a lsp the right way to go for these kinds of macros or is there some way to implement atleast some of that inside rust macro definitions?
@NoBoilerplate
@NoBoilerplate Жыл бұрын
You're quite right, it's an area of Rust that is evolving. I remember when we first started pre-compiling our javascript, and it took a while for editors to catch up! Let's be specific though, you're talking about an IDE feature, not a language feature. If someone were to write a (say) vscode plugin for Yew, you could get just the same features!
@jakob7116
@jakob7116 Жыл бұрын
​@@NoBoilerplate Yeah that makes sense. Maybe when rust gets more mainstream/popular more people will be open to making such plugins
@first-thoughtgiver-of-will2456
@first-thoughtgiver-of-will2456 Жыл бұрын
I'd love to see opencl and CUDA kernels with macros. (May already exist I need to check again). I never got into gpgpu kernels because I couldn't stand typing string literals as syntax.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
AFAIK, That is exactly what the asm!() macro does doc.rust-lang.org/rust-by-example/unsafe/asm.html I hope there's one for CUDA!
@ShaderKite
@ShaderKite Жыл бұрын
Loved this video! Traits are my favorite Rust feature, but macros are a very close second! Though, I'd appreciate it if next time maybe you mentioned some bad things as well :P E.g. here would be the cost we pay in compilation time (esp. for procedural macros)
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I've mentioned that in the past in more general Rust videos, it's a price I'm very happy to pay! :-D
@JavierHarford
@JavierHarford Жыл бұрын
May we please have some of your fantastic stylistic approach towards wasm and the like? Your explanation process is excellent 👌
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I have great news! I already wrote two videos on wasm! First video's here, the second part is 2 videos later kzbin.info/www/bejne/hmWvfpmhe7GFqas
@JavierHarford
@JavierHarford Жыл бұрын
@@NoBoilerplate 🙌 Many thanks!
@itay1232
@itay1232 Жыл бұрын
I think of macros as turning any language into a domain-specific language, excpept it's specific to every domain.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Exactly. Lisp is described as a "programmable programming language" and Rust is too!
@codenamelambda
@codenamelambda Жыл бұрын
There's one thing that I feel is very much missing in Rust macros currently - the ability to "see" the surrounding namespace to be able to query it. As is, if you see an `Option` in a macro, you do not know if it actually *is* `core::option::Option` or any other type. On a related note, afaik you can't exactly tell the compiler in which order to expand the macros such that you can keep track of some state to effectively "annotate" other types with information about them that might be useful. While you *can* do both of these things to *some* extent with traits and/or consts, it's rather difficult sometimes & in my opinion does limit the *reasonable* possibilities quite a bit. This is where I think Zig actually does this rather well - Zig has compile time only functions, which you can use to generate new types or do compile time reflection on existing types.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Oh fascinating - this is something called macro hygiene, I think? Hygenic macros only act on the scope they've been provided, and are thus easier to reason about, unhygenic macros slurp up stuff outside there scope. I could be wrong there. I'm not as familiar with zig compile time functions as you are (though I've read much). Can't you generate new times and do compile time reflection on existing types with rust macros? My understanding is that zig compile time functions can only do a subset of what rust macros can do?
@codenamelambda
@codenamelambda Жыл бұрын
@@NoBoilerplate macro hygiene isn't a way of "seeing" the environment, but rather is a way of making sure that macros don't end up having unwanted interactions with the scope in which they are expanded, by actually going it it's own "separate environment" to some extent. Say you have a macro that expands to `{ let x = foo(); bar($expr); baz() }`, then that `x` will not be visible to the expanded `$expr`, meaning it won't shadow an `x` defined in the scope in which the macro is expanded. Regarding how powerful macros / Zig functions are, pretty sure it's the other way around, Zig functions can do everything macros can but not the other way around, except for custom syntax (since functions in Zig still operate on "values", be they compile time values (which include types) or not - and not token streams). In general, in Zig you can do things like given a type find out if it's a tagged union, enum, union, struct or primitive, and even see the fields it has and their types etc. Beyond that you can also concatenate variable length slices at compile time without having to worry about allocations or lengths without issue, read files at build time, etc etc - the print function in Zig also uses the same compile time machinery: ziglang.org/documentation/0.10.1/#Case-Study-print-in-Zig So you can do pretty much everything (and if you need a DSL you can parse it from a string at least, or put it in another file) at compile time in the actual context in which you know all the context of your types etc. (It should be noted that you can get some similar stuff in Rust at least as it pertains to types with a ton of derives, but it's much more work to implement.) Meanwhile in Rust, macros just turn token streams into other token streams - if you see the token `Option`, you only know it's an identifier, and not what that identifier refers to / what traits it may implement / etc Which I should note though, is a hard problem to solve - the abstractions Rust chooses make it pretty much impossible without having a lot of metadata about each macro, especially where traits are involved. I ultimately still prefer the safety and abstraction language via traits Rust provides over Zig for actual production level stuff, but I do very much enjoy the "reflective power" and compile time goodness Zig can provide that Rust is comparatively lacking.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@codenamelambda Ah of course! Thank you for the explanation. I have enormous respect for Zig, though the minimalism of the language isn't quite for me (in the domains I work in).
@etooamill9528
@etooamill9528 Жыл бұрын
what you mean is i can design a programming language, build a macro for it in rust, write my code inside the macro, and then use the rust compiler to make an executable of it?
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Yes, with full support of the rust ecosystem and ide support. It's not even that difficult, macro_lisp is only 300 lines crates.io/crates/macro_lisp
@etooamill9528
@etooamill9528 Жыл бұрын
@@NoBoilerplate oho this is exiting! I'll definitely try and play with it, it'll definitely be easier to learn macros than build a compiler or interpreter, which was the thing that was holding me back from even entertaing the idea of designing a programming language!
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@etooamill9528 You'll learn different things making a language outside of rust, so by all means do it the old fashioned way for learning! But if you're doing it to solve problems... do it INSIDE rust! XD
@etooamill9528
@etooamill9528 Жыл бұрын
@@NoBoilerplate you are right, even if it's scary I'll never learn if i don't get out of my comfort zone
@KohuGaly
@KohuGaly Жыл бұрын
...well... kinda but not really... A procedural macro is just a program that takes a token stream and spits out a token stream. If you want to write a new language in it, then you'll basically be writing a transpiler/compiler to transform your code into valid rust. What proc-macro gives you in this context is the ability to then use that language inline inside any rust program.
@_schwm
@_schwm Жыл бұрын
3:20 ngl, creating implementation with declarative macros hasn't crossed my mind. it's genius.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I suspect we're only just (re)learning, as an industry, how to use macros!
@AlexEscalante
@AlexEscalante 5 ай бұрын
Súper bueno! i wan't aware Rust macros where so different. I am liking Rust a lot!
@NoBoilerplate
@NoBoilerplate 5 ай бұрын
Cool right! If Rust didn't have macros (my favourite feature from lisp) - we wouldn't be speaking, I'd be using Haskell or Go - terrible! :-D
@AlexEscalante
@AlexEscalante 5 ай бұрын
@@NoBoilerplate hahaha… I tried Go last year and really didn't like it a lot. Since I already know C++ and C#, I really needed something comparable. Rust makes a lot of sense to me.
@NoBoilerplate
@NoBoilerplate 5 ай бұрын
@@AlexEscalante hehe, yes Ken Thompson and Co were rather blinkered when they made go, I think. They tried for "cpp but modern" and I believe they succeeded wildly. But I need more than that 😅
@mskiptr
@mskiptr Жыл бұрын
Are macro_rules typechecked at call-site or definition-site?
@KohuGaly
@KohuGaly Жыл бұрын
call site. Although the error gets reported at the definition site, with clause that says "The error originated in macro expansion here [file, line and column of the call site]"
@josefaguilar2955
@josefaguilar2955 Жыл бұрын
I love the power of the macros but I can imagine a scenario where the DB a macro pulls from changes or is missing and that breaks compilation. Might be a great security feature though.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Sure, just like when you run your project and it tries to connect to a database and it says "db not found", or if the db changes and suddenly your schema is out of data in your running app. With sqlx you get that feedback *immediately*, which I love. Early errors are much better than late errors! Honestly, that's the Rust thesis right there :-)
@Capharas
@Capharas 4 ай бұрын
What? That's so cool! Why didn't I know about this?
@kelvinpraises
@kelvinpraises Жыл бұрын
I didn't understand everything but I was blown away
@NoBoilerplate
@NoBoilerplate Жыл бұрын
honestly same, that's why I'm here :-)
@kelvinpraises
@kelvinpraises Жыл бұрын
@@NoBoilerplate Thanks!
@nyxalexandra-io
@nyxalexandra-io Жыл бұрын
Was just thinking about how you would probably release a video soon
@NoBoilerplate
@NoBoilerplate Жыл бұрын
That's Pavlovian conditioning: I release every other Friday :-)
@lorenzoreyes1692
@lorenzoreyes1692 Жыл бұрын
Can I ask you what you use to make this presentation? Vainilla Power Point?
@katech6020
@katech6020 Жыл бұрын
he linked it in the video, they are markdown files with testable code, similar to rust docs
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Powerpoint? Ew! As I say in the videos, my presentations are built with markdown, I use obisidan.md as my editor and advanced-slides as my plugin github.com/0atman/noboilerplate/tree/main/scripts you should give obsidian.md a try! Take back control! I talked about Obsidian in the middle of this video kzbin.info/www/bejne/n5fEfZ5rq5iKb5I
@lorenzoreyes1692
@lorenzoreyes1692 Жыл бұрын
@@NoBoilerplate Thanks sir, I am surprised this tool will come really helpful as I was looking a tool like this to teach python
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@lorenzoreyes1692 My pleasure, obsidian.md is a fantastic tool, like a personal knowledge base, with loads of plugins that make it great for programming too! Also, try Jupyter Notebook for teaching python, and repl.it. Good luck!
@shankarsengupta1948
@shankarsengupta1948 10 ай бұрын
Rust seems quiet beautiful - I would love to try. Also, at 8:40 an incorrect statement is made claiming "To get this compile time features in other languages, you must wait for the language or pre-compiler authors to update their code". Languages like common lisp and scheme have supported macros for many many decades now.
@NoBoilerplate
@NoBoilerplate 10 ай бұрын
Ah lisp, my beloved! Yes of course, as I have said many times, Rust is like Haskell and Lisp snuck into the cool languages party in C's clothing!
@G0NZA11
@G0NZA11 Жыл бұрын
Is there a way to create a macro that makes automatic type conversion by name? Like JavaScript, in which { ...other } makes every x = x being x a property of the object
@NoBoilerplate
@NoBoilerplate Жыл бұрын
I don't quite understand what you want here, are you talking about the struct update syntax: doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
@G0NZA11
@G0NZA11 Жыл бұрын
@@NoBoilerplate yes, but no. You cannot do that if you have a User struct and a, let's say, Person. Can that problem be resolve with macros? A macro that implements the from and into method automatically?
@NoBoilerplate
@NoBoilerplate Жыл бұрын
@@G0NZA11 Huh, I see. A macro would be perfect for that, yes!
@justsomeonepassingby3838
@justsomeonepassingby3838 6 ай бұрын
I thought Rust macros could not compete with Lisp macros (seriously, who would dare bootstrap object oriented classes in any language other than Lisp ?) because lisp relies on abstractions like dynamic typing or garbage collection, which are not possible in Rust, in order to maximize expressivity and minimize the syntax. But this video proves me wrong, implementing html and sql as Rust DSLs seems to be as much power as one could get from Lisp. Rust is indeed the ultimate language. Actually, there is still one thing i haven't seen Rust do yet: continuations But i think a continuation passing style macro would be no problem for Rust
@NoBoilerplate
@NoBoilerplate 6 ай бұрын
Certainly you could implement them using macros, just as CL does - this is how async/await was prototyped in Rust at first, but it's now a native language feature! rust-lang.github.io/async-book/03_async_await/01_chapter.html
@jmrumble
@jmrumble 11 ай бұрын
Every time I stumble upon these videos my brain goes “Hey it’s the lost terminal voice” 😂 (even though I found that because of this channel, it made such an impression 😊)
@NoBoilerplate
@NoBoilerplate 11 ай бұрын
Hehe!
@brunao544
@brunao544 10 ай бұрын
You mentioned syntax highlighting works for VS Code using the html_to_string_macro but for some reason I can't get it to work.
@NoBoilerplate
@NoBoilerplate 10 ай бұрын
Have you got rust_analyzer working? I just opened up the same "my blog" demo as in this video in vscode and it looks great - proper html formatting detected inside the macro. HONESTLY I don't know how it does this, the formatting doesn't work as nicely in my nvim editor XD Paste some screenshots into #newbie-advice on my discord and ask for help if you need it!
@brunao544
@brunao544 10 ай бұрын
@@NoBoilerplate You're the man! I have rust-analyzer, uninstalled it a bunch of times but still nothing.
@NoBoilerplate
@NoBoilerplate 10 ай бұрын
@@brunao544 hmm, there aren't many moving parts here: update vscode, update rust with rustup update nightly (use nightly to be sure) and update the vscode rust analyser plugin!
@MaxPicAxe
@MaxPicAxe Жыл бұрын
2:41 the space after the left bracket hurts me
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Well spotted! You found the bug in my reveal.js plugin, it HATES those dollar signs, some kind of escaping bug? I had to hand-edit these macro slides to fix them. DISLIKE! My bug report is here FYI github.com/MSzturc/obsidian-advanced-slides/issues/193
@alkeryn1700
@alkeryn1700 Жыл бұрын
i once wrote a proc_macro that would take an arbitrary amount of iterator and generate a sql bulk query from them because the library i was using didn't support it.
@NoBoilerplate
@NoBoilerplate Жыл бұрын
Perfect!
@naranyala_dev
@naranyala_dev Жыл бұрын
thank you
@NoBoilerplate
@NoBoilerplate Жыл бұрын
My pleasure :-)
@etopowertwon
@etopowertwon Жыл бұрын
7:57 speaking of, what IDE/editor is it?
@NoBoilerplate
@NoBoilerplate Жыл бұрын
oh ho ho! You are in for a TREAT astronvim.github.io/ If you need help setting it up, ping me on my discord!
@wontcreep
@wontcreep Жыл бұрын
i'm buying whatever you're selling rn, man, such passion
@NoBoilerplate
@NoBoilerplate Жыл бұрын
My real passion is not getting paged by another syntax error in production at 4am
@XzcutioneR2
@XzcutioneR2 Жыл бұрын
Narrator: *talks about macros, HTML syntax within rust etc etc. Me who started learning the language 3 days ago: o.O
@NoBoilerplate
@NoBoilerplate Жыл бұрын
You're going to have an *incredible* time learning Rust! Do ask questions in #newbie-advice on my discord if you get stuck, and read The Book! doc.rust-lang.org/stable/book/
How to Learn Rust
10:36
No Boilerplate
Рет қаралды 513 М.
Rust is not a faster horse
11:37
No Boilerplate
Рет қаралды 317 М.
Заметили?
00:11
Double Bubble
Рет қаралды 3 МЛН
The Worlds Most Powerfull Batteries !
00:48
Woody & Kleiny
Рет қаралды 24 МЛН
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,2 МЛН
1❤️
00:20
すしらーめん《りく》
Рет қаралды 33 МЛН
NixOS: Everything Everywhere All At Once
15:10
No Boilerplate
Рет қаралды 259 М.
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 57 М.
NixOS Secrets Management - Part 1/3
12:40
EmergentMind
Рет қаралды 4,6 М.
Rust: Turtles all the way down
11:21
No Boilerplate
Рет қаралды 160 М.
rust macros are magic
14:02
Tantan
Рет қаралды 44 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 133 М.
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 125 М.
The Unreasonable Effectiveness Of Plain Text
14:37
No Boilerplate
Рет қаралды 573 М.
Procedural Macros in Rust
11:33
Let's Get Rusty
Рет қаралды 39 М.
Заметили?
00:11
Double Bubble
Рет қаралды 3 МЛН