A Practical Introduction to Derive Macros in Rust

Sdílet
Vložit
  • čas přidán 8. 06. 2024
  • In this video, we will learn about derive macros in Rust, which is a subtype of procedural macros. We will code a simple example to understand the concept of derive macros. Also, we will delve into the world of procedural macros, the differences between procedural and declarative macros, and how procedural macros are generated during compile time. We will see a gentle introduction to the syn and quote crates as well.
    Links:
    Procedural macros reference: doc.rust-lang.org/reference/p...
    Derive macros section in procedural macros reference: doc.rust-lang.org/reference/p...
    syn documentation: docs.rs/syn/
    quote documentation: docs.rs/quote/
    Song Attributes:
    Jazzy Hip Hop Boom Bap by Music Unlimited
    Lofi Vibes by chillmore
    Lofi Vintage by FASSounds
    Sweet Chillhop by Music Unlimited
    Untitled Lofi by hour
    Follow me on my socials:
    Blog: erayerdin.com/
    Github: github.com/erayerdin
    Twitter: / _erayerdin
    Stackoverflow: stackoverflow.com/users/29269...
    Telegram: t.me/erayerdin
    00:00 Introduction
    01:30 Example Case
    02:13 Manual Implementation
    03:28 Writing Procedural Macros
    09:09 Outro

Komentáře • 37

  • @shimonpertz
    @shimonpertz Před 3 měsíci +4

    Clear language, high level of explaining and simple to understand, neat slides. Liked and Subscribed.
    Keep up the good work mate!

  • @hahaheheh0h0
    @hahaheheh0h0 Před rokem +9

    I happened to chance upon your videos on reddit.
    i had a hard time learning about macros from the book, and the clarity of your explanations is simply amazing.
    thanks for all the tutorial videos!
    they are of tremendous help!
    I can't wait for your subsequent videos.

    • @_schwm
      @_schwm  Před rokem +1

      Thank you so much. 😊

  • @cthutu
    @cthutu Před 11 měsíci +2

    Really good video - with syn and quote, writing powerful macros is more effortless.

  • @proud22beme
    @proud22beme Před 10 měsíci +1

    Thank you SOOOO MUCH for making this!
    The topic of proc-macros was intimidating for me to even approach because of my perceived difficulty and complexity of them.
    With how concise and clear this is written and done, and even explaining all the nuisances, and the reasoning for each part, it really makes proc-macros way more approachable!
    Huge thanks for taking the time to write and record this, its a HUGE help to get a understanding of what they really are, and how to start writing them~

    • @_schwm
      @_schwm  Před 10 měsíci

      You're so welcome! 😊

  • @TON-vz3pe
    @TON-vz3pe Před 5 měsíci

    This is quality content. You explained the things which I considered complex with a simple example and easy words.

  • @dimiutube
    @dimiutube Před 4 měsíci

    Short and easy to understand! Thank you very much!

  • @pmmeurcatpics
    @pmmeurcatpics Před měsícem

    Awesome video!

  • @yapayzeka
    @yapayzeka Před rokem +3

    proud of finding this very good quality channel this early

    • @_schwm
      @_schwm  Před rokem

      Thank you. 😊

    • @yapayzeka
      @yapayzeka Před rokem

      @@_schwm cant wait for tutorials about basic and advanced use of traits (blanket implementaitons, trait objects etc) and generics. Your examples and way to explain things are very very catchy.

    • @albertz0
      @albertz0 Před rokem

      same here. Rust... so much to learn, so interesting.

  • @slava_in3757
    @slava_in3757 Před rokem +6

    Nice video, waiting for more on attribute and function macros

    • @_schwm
      @_schwm  Před rokem +3

      Will be there in next 5 weeks I believe. Thank you. 🩶

    • @_erayerdin
      @_erayerdin Před 10 měsíci +1

      Forgot to inform, it's been out.

  • @yaksher
    @yaksher Před 8 měsíci +2

    @0:20 Function-like macros can also be procedural, though all declarative macros are function-like. Declarative macros are macros defined via macro_rules! and procedural macros are defined via proc_macro and run arbitrary Rust.

  • @omestredd3
    @omestredd3 Před rokem

    This is really amazing tutorial! I also stumbled upon it in reddit. Great job! thank yo uso much!

    • @_schwm
      @_schwm  Před rokem

      Thanks for watching. ☺️

  • @kyrylogorbachov3779
    @kyrylogorbachov3779 Před 2 měsíci

    Excellent explanation! Thank you. Just a bit too fast for me. Felt like some seconds in between the concepts where needed for thinking. Ofacause pause is an option.

  • @aperson4051
    @aperson4051 Před rokem +1

    Very good!!

  • @obichinedufrank
    @obichinedufrank Před 11 měsíci

    Thank you 😊

  • @InMemoryOfNeo
    @InMemoryOfNeo Před 7 měsíci

    awesomeeee 👏👏👏👏👏👏👏👏👏👏👏

  • @skytech2501
    @skytech2501 Před 7 měsíci

    you are awesome!

  • @GlobalYoung7
    @GlobalYoung7 Před rokem

    thank you 😊

    • @_schwm
      @_schwm  Před rokem +1

      You're welcome 😊

  • @discobiscuit8955
    @discobiscuit8955 Před 8 měsíci

    Thanks for the vid! Can you tell me what color scheme you're using? It's very pleasing.

  • @Robert-ht5kd
    @Robert-ht5kd Před rokem +1

    3:03 What is that terminal?

    • @_schwm
      @_schwm  Před rokem

      It's fish and tide. After you install fish, you can install fisher (fish package manager) and then tide here: github.com/jorgebucaran/awsm.fish

  • @GustavoAVerde
    @GustavoAVerde Před 9 měsíci

    What kind of sorcery is this!!??

    • @_schwm
      @_schwm  Před 8 měsíci +2

      Unless you don't want to generate some code, writing macros is totally optional. So, a sorcery you can ignore indeed, my friend.

  • @PrimeGoose
    @PrimeGoose Před rokem +1

    love me pls😇

  • @wolfeygamedev1688
    @wolfeygamedev1688 Před 11 měsíci

    I followed allong until the !vec[#(#field_idents),*] syntax, that made my brain unhappy

    • @_schwm
      @_schwm  Před 11 měsíci +2

      let me explain it by oversimplifying.
      `#var_name` is a special syntax for `quote::quote!` to generate code with variables that come before it.
      if your variable outside `quote::quote!` is a very simple type like string or integer, then inside `quote::quote!`, you can simply use `#var_name`.
      but, if `#var_name` is an array or vector, you should use `#(#var_name),*`, and possibly wrap it inside a `vec![]`.
      the reason why you do this if `#var_name` is a vector or array is because, while you're generating code, you need to iterate over each element inside `var_name`. so you can say `#(),*` is like a for-each loop while generating code.

    • @wolfeygamedev1688
      @wolfeygamedev1688 Před 11 měsíci

      @@_schwm sum it up is just way to make vec with field identifier strings in it. I just hate the syntax...