danlogs
danlogs
  • 56
  • 154 514
Advanced Declarative Macros in Rust
Check out my course here: www.udacity.com/course/intro-to-rust--cd13678?coupon=DANBUGS40
- danlogs git repository: github.com/danbugs/danlogs/
- danlogs discord server: discord.gg/fSWE49H
- Follow me on Twitter: danologue/
- Follow me on GitHub: github.com/danbugs/
- For business inquiries, contact me on LinkedIn: www.linkedin.com/in/danbiz
มุมมอง: 450

วีดีโอ

Method Overloading (kinda), and Advanced Trait Usage - Quick Rust
มุมมอง 1.8Kปีที่แล้ว
- danlogs git repository: github.com/danbugs/danlogs/ - danlogs discord server: discord.gg/fSWE49H - Follow me on Twitter: danologue/ - Follow me on GitHub: github.com/danbugs/ - For business inquiries, contact me on LinkedIn: www.linkedin.com/in/danbiz
Unsafe - Rust
มุมมอง 1.2Kปีที่แล้ว
00:00:00 Introduction 00:00:31 Raw Pointers 00:02:58 Dereferencing Raw Pointers 00:04:12 static mut 00:06:26 Conclusion - danlogs git repository: github.com/danbugs/danlogs/ - danlogs discord server: discord.gg/fSWE49H - Follow me on Twitter: danologue/ - Follow me on GitHub: github.com/danbugs/ - For business inquiries, contact me on LinkedIn: www.linkedin.com/in/danbiz
Things You Might Not Know About match - Quick Rust
มุมมอง 1.3Kปีที่แล้ว
Things covered in this video: - destructuring, - | operator - .. operator, - ..= operator, - 𝚖𝚊𝚝𝚌𝚑 guards, - @ bindings, and - 𝚛𝚎𝚏 / 𝚛𝚎𝚏 𝚖𝚞𝚝 - danlogs git repository: github.com/danbugs/danlogs/ - danlogs discord server: discord.gg/fSWE49H - Follow me on Twitter: danologue/ - Follow me on GitHub: github.com/danbugs/ - For business inquiries, contact me on LinkedIn: www.linkedin.com/...
Multithreading, Message Passing (crossbeam-channel), Arc/Mutex, and Send/Sync - Rust
มุมมอง 5Kปีที่แล้ว
00:00:00 Introduction 00:02:10 Fearless vs Fearful Concurrency 00:05:12 Basics 00:07:57 Joining Threads 00:11:52 Capturing Variables In Our Scope To Use In A Thread 00:13:29 Message Passing 00:16:06 Bounded Channels 00:18:21 Multiple Receivers and Non Blocking Receive 00:21:36 Mutex and Arc 00:27:05 Threading and Generics with Send Sync then Conclusion - danlogs git repository: github.com/danbu...
AsRef/Borrow Traits, and the ?Sized Marker - Rust [Video Request]
มุมมอง 4.8K2 ปีที่แล้ว
00:00:00 Prologue 00:00:34 Introducing Borrow 00:03:58 Implementing Borrow for Our Own Type, and Seeing Its' Utility 00:17:12 (Aside) ?Sized 00:20:54 (cont'd) Implementing Borrow for Our Own Type, and Seeing Its' Utility 00:22:12 Introducing AsRef - and differentiating it from Borrow 00:23:55 Going Back to Our Example from Before - How Do Borrow and AsRef Differ? - danlogs git repository: githu...
Rc and RefCell Smart Pointers - Rust
มุมมอง 8K2 ปีที่แล้ว
00:00:00 Prologue 00:00:20 What is the Rc Smart Pointer? 00:01:50 Breaking the Single Ownership Rule 00:05:40 What is the RefCell Smart Pointer? 00:07:20 Breaking the Mutability Rule 00:11:00 Mutating Data with Several Owners 00:14:10 Rc and RefCell can Leak Memory 00:20:20 Preventing a Memory Leak by Using Weak Instead of Rc Chapters 15.4, 15.5, and 15.6 - danlogs git repository: github.com/da...
Deref and Drop Traits - Rust
มุมมอง 2.9K2 ปีที่แล้ว
00:00:00 Introduction 00:00:12 What is the Deref trait? 00:01:38 Creating a Smart Pointer to implement the Deref trait for 00:02:39 Implementing the Deref trait 00:03:52 Quick Aside Associated Types 00:10:14 Continuing the implementation of the Deref trait 00:12:03 Closing notes on Deref 1 Deref coercion 00:14:58 Closing notes on Deref 2 DerefMut 00:17:21 Closing notes on Deref 3 Deref coercion...
Why should you learn WebAssembly?
มุมมอง 1.4K3 ปีที่แล้ว
00:00:00 Introduction 00:00:55 Why should you learn WebAssembly? 00:01:48 Improving the performance of your code on the web 00:11:26 Allowing code-reuse when porting Desktop applications and such 00:13:43 What can you expect for this series? - Gerard Gallant's Web Assembly in Action book on Amazon: www.amazon.com/WebAssembly-Action-Gerard-Gallant/dp/1617295744/ref=sr_1_1?dchild=1&keywords=webas...
I'm back!
มุมมอง 5513 ปีที่แล้ว
- danlogs git repository: github.com/danbugs/danlogs/ - danlogs discord server: discord.gg/fSWE49H - Follow me on Twitter: danologue/ - Follow me on GitHub: github.com/danbugs/ - For business inquiries, contact me on LinkedIn: www.linkedin.com/in/danbiz
Building a Game | Rust Project
มุมมอง 10K3 ปีที่แล้ว
00:00:00 Introduction 00:00:53 What are we use? 00:02:50 Getting ready & creating a window 00:08:49 How did we create a window? 00:13:52 Seeing the world through a camera 00:19:17 Adding Pikachus 00:38:22 Moving the Pikachus 00:57:36 Creating a Pokeball 01:03:48 Can't defy gravity 01:08:51 Make the Pokeball bounce 01:23:18 Keep the score 01:43:01 The music 01:57:57 Closing statement - Debian/Ub...
Text-Based and Graphical User Interfaces | Rust Project
มุมมอง 27K4 ปีที่แล้ว
The TUI introduction was so long that I decided to cut directly to the GUI w/ no transition 🤣 00:00 Prologue 00:24 What are we building? 02:07 Buiding a Text-Based User Interface 05:38 Showing a Dialog Box 07:47 Handle Simple Keyboard Inputs 09:53 Adding a Dialog 11:14 Multi-step dialogs 16:35 Building a Graphical User Interface 21:58 Displaying an Image 26:09 Using Glade to Design the UI 34:13...
Palindrome Number Problem - Leet Code + Rust
มุมมอง 9294 ปีที่แล้ว
- danlogs git repository: github.com/danbugs/danlogs/ - danlogs discord server: discord.gg/fSWE49H - Follow me on Twitter: danologue/ - Follow me on GitHub: github.com/danbugs/ - For business inquiries, contact me on LinkedIn: www.linkedin.com/in/danbiz
Reverse Integer Problem - Leet Code + Rust
มุมมอง 7414 ปีที่แล้ว
Reverse Integer Problem - Leet Code Rust
Command Line Program | Rust Project
มุมมอง 3.4K4 ปีที่แล้ว
Command Line Program | Rust Project
Introduction | Rust Projects
มุมมอง 1.5K4 ปีที่แล้ว
Introduction | Rust Projects
Two Sum Problem - Leet Code + Rust
มุมมอง 3.1K4 ปีที่แล้ว
Two Sum Problem - Leet Code Rust
Introduction - Leet Code + Rust
มุมมอง 1.3K4 ปีที่แล้ว
Introduction - Leet Code Rust
Smart Pointers & Box - Rust
มุมมอง 5K4 ปีที่แล้ว
Smart Pointers & Box - Rust
Iterators - Rust
มุมมอง 3.5K4 ปีที่แล้ว
Iterators - Rust
Closures - Rust
มุมมอง 4.1K4 ปีที่แล้ว
Closures - Rust
Testing - Rust
มุมมอง 2.7K4 ปีที่แล้ว
Testing - Rust
An Announcement!
มุมมอง 4774 ปีที่แล้ว
An Announcement!
Lifetimes - Rust
มุมมอง 12K4 ปีที่แล้ว
Lifetimes - Rust
Traits - Rust
มุมมอง 2.4K4 ปีที่แล้ว
Traits - Rust
Generics - Rust
มุมมอง 1.6K4 ปีที่แล้ว
Generics - Rust
Quick `?` Operator - Rust
มุมมอง 1.8K4 ปีที่แล้ว
Quick `?` Operator - Rust
Error Handling - Rust
มุมมอง 3K4 ปีที่แล้ว
Error Handling - Rust
Tables - WebAssembly
มุมมอง 6004 ปีที่แล้ว
Tables - WebAssembly
"Hello, World!" in WebAssembly Text Format
มุมมอง 1.7K4 ปีที่แล้ว
"Hello, World!" in WebAssembly Text Format

ความคิดเห็น

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz 20 วันที่ผ่านมา

    but if there's just one statement, shouldn't it expand to: "1 <<" (removing the redundant stringify). How does that parse? There's a dangling left-shift operator without a number after it.

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 20 วันที่ผ่านมา

      Ok I checked macro's expansion, apparently it's smart enough to treat the joining only when.. you guessed it, joining. I.e its behaviour is similar to string.join(iterable) in Python or iterator.join(string) in Rust.

  • @Palawusa
    @Palawusa หลายเดือนก่อน

    14:00 The fact that I watched this video before and still used mspc channels makes me so mad right now lol

  • @roxferesr
    @roxferesr 4 หลายเดือนก่อน

    You are passing Referenced to the RC.... Wouldn't just using references work in the original code without the RC

  • @RahulYadav-dd7qe
    @RahulYadav-dd7qe 4 หลายเดือนก่อน

    Suggestion to work on volume.

  • @anujdhiman6640
    @anujdhiman6640 5 หลายเดือนก่อน

    Hi Danlogs, Nice explanation but i would recommend one thing to show output automatically without cargo run , install cargo watch and run he command - cargo watch -q -c -x 'run -q' It will save your time in video too.

  • @sankalpchordia5245
    @sankalpchordia5245 6 หลายเดือนก่อน

    Why did you stop the series ?

    • @danlogs
      @danlogs 5 หลายเดือนก่อน

      Hey - I just haven't had all that much time to work on the channel recently, definitely planning to come back to it whenever possible though!

  • @christianfrancesconi3456
    @christianfrancesconi3456 6 หลายเดือนก่อน

    Rust concurrency now crystal clear. Thanks !

  • @luiscarlosjayk
    @luiscarlosjayk 7 หลายเดือนก่อน

    Nice explanation!!!

  • @AyoDamilareMichael-g3y
    @AyoDamilareMichael-g3y 7 หลายเดือนก่อน

    Awesome video ❤

  • @coalabi6850
    @coalabi6850 7 หลายเดือนก่อน

    Really nice and useful video. Well explained!

  • @JuanPerez-rj7on
    @JuanPerez-rj7on 8 หลายเดือนก่อน

    Would be amazing to see an update video with component model. 😊

    • @danlogs
      @danlogs 5 หลายเดือนก่อน

      That is definitely in the plans!

  • @JuanPerez-rj7on
    @JuanPerez-rj7on 8 หลายเดือนก่อน

    Hey Dan, amazing content!! Will follow up with the series.

  • @flippert0
    @flippert0 10 หลายเดือนก่อน

    Great insights, thanks!

  • @prashlovessamosa
    @prashlovessamosa 10 หลายเดือนก่อน

    Thanks man

  • @Sofronov_channel
    @Sofronov_channel 11 หลายเดือนก่อน

    More videos ❤

  • @C2H6Cd
    @C2H6Cd 11 หลายเดือนก่อน

    I couldn't figure out which web-based Rust code editor you use in this video. Could you give a hint about it?

    • @danlogs
      @danlogs 11 หลายเดือนก่อน

      Hey! It's not really a code editor - I just used mdbook: crates.io/crates/mdbook You can see my source code for it here: github.com/danbugs/danlogs/tree/master/Rust/The%20Rust%20Programming%20Language%20-%20Tutorials/extra/asref_borrow

  • @cruchitect
    @cruchitect ปีที่แล้ว

    tysm!

  • @Randych
    @Randych ปีที่แล้ว

    Content seems alright, but from sound perspective it's very tiresome on the ears.

  • @yotubecreators47
    @yotubecreators47 ปีที่แล้ว

    this is cool, deep dive

  • @mohaniya15
    @mohaniya15 ปีที่แล้ว

    Dude dont stop making videos, youre the only one whose video i can watch once and understand everything

  • @mohaniya15
    @mohaniya15 ปีที่แล้ว

    There are so many videos that i have watched that dont explain lifetimes as an "agreement with the compiler" or show what benefits it provides to the user, this video made me understand all of it completely! Thanks a lot, subscribed!

    • @danlogs
      @danlogs ปีที่แล้ว

      This kind of comment is what keeps me going - Thank you!

  • @liveonphoenix5045
    @liveonphoenix5045 ปีที่แล้ว

    @21:30, Hello, could you kindly provide some clarification on the whereabouts of the 'Coordinate' object or instance? I'm curious whether you employed any form of code optimization, such as elision, or if you implicitly utilized it in a way we don't get/catch up. Thank you in advance, and your explanation is truly well-done.

    • @danlogs
      @danlogs 11 หลายเดือนก่อน

      Hey - apologies on the delay getting back to you. That was actually a mistake on my part. I meant to make use of it, but, iirc, I just kind of forgot about the struct. I have a (now) pinned comment on this video w/ further details on how I intended to use it.

  • @midewestmond9442
    @midewestmond9442 ปีที่แล้ว

    Please use dark mode

    • @danlogs
      @danlogs ปีที่แล้ว

      Any specific reason why? I’ve recently taken a liking to having it like this (:

    • @SKrandy
      @SKrandy 8 หลายเดือนก่อน

      My eyes are torn... ​@@danlogs

  • @albertoromero1934
    @albertoromero1934 ปีที่แล้ว

    Kinda polymorphism, kinda method overload, kinda everything 😂 great video!!

  • @alexplosivo7966
    @alexplosivo7966 ปีที่แล้ว

    Love this, so helpful

  • @matteac_rs
    @matteac_rs ปีที่แล้ว

    macros are magic, you're not supposed to touch them🦀🪄

  • @MichaelKefeder
    @MichaelKefeder ปีที่แล้ว

    The last example can be called like this too fn main() { MyStruct::method(1); MyStruct::method(1.0); } because the compiler picks the correct trait-method by the arguments data-type. Nice video, reminded me again that this is doable in Rust :)

    • @danlogs
      @danlogs ปีที่แล้ว

      Good catch! I'm glad you liked the video ;D

  • @faeancestor
    @faeancestor ปีที่แล้ว

    im not sure if I understand the meaning of the star symbol here

    • @danlogs
      @danlogs ปีที่แล้ว

      The star symbol means: "zero or more". We see its usage in this example to match "zero or more" statements. Take this simpler macro, for example: 𝚖𝚊𝚌𝚛𝚘_𝚛𝚞𝚕𝚎𝚜! 𝚙𝚛𝚒𝚗𝚝_𝚊𝚕𝚕 { ($($𝚜:𝚕𝚒𝚝𝚎𝚛𝚊𝚕),*) => { // receiving one of more literals (like: i32s, &strs, etc.) separated by commas $( 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("{}", 𝚜𝚝𝚛𝚒𝚗𝚐𝚒𝚏𝚢!($𝚜)); )* // one println! per literal we match } } 𝚏𝚗 𝚖𝚊𝚒𝚗() { 𝚙𝚛𝚒𝚗𝚝_𝚊𝚕𝚕!(𝟷, 𝟸, 𝟹); // we're passing in 3 literals } Because of the star symbol, our 𝚖𝚊𝚒𝚗, in simplified form, expands to: 𝚏𝚗 𝚖𝚊𝚒𝚗() { { 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("{}", 𝚜𝚝𝚛𝚒𝚗𝚐𝚒𝚏𝚢!(𝟷)) }; { 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("{}", 𝚜𝚝𝚛𝚒𝚗𝚐𝚒𝚏𝚢!(𝟸)) }; { 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("{}", 𝚜𝚝𝚛𝚒𝚗𝚐𝚒𝚏𝚢!(𝟹)) }; ; } I hope this helps!

  • @ghashy4501
    @ghashy4501 ปีที่แล้ว

    Thanks! It was very informative, and in the end I did understand the difference between two of them :)

  • @rolv529
    @rolv529 ปีที่แล้ว

    I agree the audio could be a bit higher but honestly it's fine, great video though thanks for making it

  • @hlavaatch
    @hlavaatch ปีที่แล้ว

    Audio levels seem too low

    • @danlogs
      @danlogs ปีที่แล้ว

      Oh, my bad - I didn't really change my mic setup from the last video, but I'll try speak closer to it next time (:

    • @hlavaatch
      @hlavaatch ปีที่แล้ว

      You can just normalize the audio in a video editing tool no?

    • @danlogs
      @danlogs ปีที่แล้ว

      @@hlavaatch ~ not afaik.

  • @MichaelKefeder
    @MichaelKefeder ปีที่แล้ว

    the std::sync::mpsc is using crossbeam under the hood since ~Feb 2022, if no other features of crossbeam are used, you can avoid a dependency :)

    • @danlogs
      @danlogs ปีที่แล้ว

      That's true, github.com/rust-lang/rust/pull/93563 was merged just this past November 🎉 ~With that said, afaik, there's still no way to fulfill the multiple-producer-multiple-consumer pattern w/ the standard library's crate as `std::sync::mpmc` is still private: play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3650e906a764237c3d49cd572610a289

    • @osgiliath_burns
      @osgiliath_burns หลายเดือนก่อน

      @@danlogs what is the advantage of the multiple consumer pattern? Is it faster? I don't see the advantage of that over having a single consumer in the main function that is receiving all messages

    • @danlogs
      @danlogs 27 วันที่ผ่านมา

      @@osgiliath_burns ~ It's not really about performance but more about the fact that sometimes, you just need multiple consumers. For example, say you have a system receiving different types of data, like temperature readings, humidity levels, and error messages from sensors. Instead of one consumer sorting and handling everything, you could have: - One consumer dedicated to handling temperature data, - Another for humidity, - And a third just for error messages. This way, each consumer only deals with what it needs to, making the code cleaner and easier to work with when you’re handling multiple tasks at once.

  • @hilal53426
    @hilal53426 ปีที่แล้ว

    Thanks for uploading this and keep up the good work!

  • @shadowxp951
    @shadowxp951 ปีที่แล้ว

    Ah finally a new video. I really appreciate your videos. Thanks!

  • @rx80
    @rx80 ปีที่แล้ว

    Been a lil bit 🤏

  • @MrAnandml
    @MrAnandml ปีที่แล้ว

    Oh this is some excellent Rust content 👌

  • @hilal53426
    @hilal53426 ปีที่แล้ว

    This is still a great video in 2023!

  • @tochithebedford7672
    @tochithebedford7672 ปีที่แล้ว

    okay i’m sold

  • @lauti7956
    @lauti7956 ปีที่แล้ว

    Hey! great video, it really helped me a lot. I just want to mention that actually the statement: `fhm.get("key")` would return None and not the incorrect value. That is due to the difference on `Hash` trait implementation for `str` and `CaseInsensitiveString`.

    • @danlogs
      @danlogs ปีที่แล้ว

      Hey - sorry for taking a while to get back to you! To clarify, 𝙲𝚊𝚜𝚎𝙸𝚗𝚜𝚎𝚗𝚜𝚒𝚝𝚒𝚟𝚎𝚂𝚝𝚛(..) implements the equality traits so that 𝙲𝚊𝚜𝚎𝙸𝚗𝚜𝚎𝚗𝚜𝚒𝚝𝚒𝚟𝚎𝚂𝚝𝚛("𝚔𝚎𝚢") == 𝙲𝚊𝚜𝚎𝙸𝚗𝚜𝚎𝚗𝚜𝚒𝚝𝚒𝚟𝚎𝚂𝚝𝚛("𝙺𝙴𝚈"), so 𝚏𝚑𝚖.𝚐𝚎𝚝("𝚔𝚎𝚢") will return 𝙲𝚊𝚜𝚎𝙸𝚗𝚜𝚎𝚗𝚝𝚒𝚝𝚒𝚟𝚎𝚂𝚝𝚛("𝚅𝙰𝙻𝚄𝙴"), which, in concept, is incorrect - i.e., we got a 'hash' collision for two keys that should not match. This is to highlight that, w/ this, we should use 𝙰𝚜𝚁𝚎𝚏, as the equality traits don't work the same and that's a usage requirement between the borrowed and owned type for 𝙱𝚘𝚛𝚛𝚘𝚠.

  • @markday3145
    @markday3145 ปีที่แล้ว

    3:50 Wouldn't n3.clone() work just as well as Rc::clone(&n3) ? The first looks a little cleaner to me. But is there a reason to prefer the second form?

    • @danlogs
      @danlogs ปีที่แล้ว

      They're equivalent in terms of functionality, but some may argue that one could be more readable than the other (i.e., 𝚁𝚌::𝚌𝚕𝚘𝚗𝚎(&𝚗𝟹) is clearer in its intent of simply creating a shared reference and not a deep clone the data as .𝚌𝚕𝚘𝚗𝚎() sometimes does.)

  • @jeffg4686
    @jeffg4686 ปีที่แล้ว

    AsRef is weird. I still haven't fully absorbed it. Borrow is weird too. Thanks for the video. The case sensitive aspect makes sense now. It's interesting that they have the same trait signature, but I guess it's just that the intent is different, so made sense to have 2. And just that the ownership semantics are different. You Borrow<T> from an owned, and you AsRef<T> from a ref. You can AsRef to many different types, so it's not just "the one and only thing inside". What I figured out is it's really just about flexibility of APIs? "As long as you can as_ref to the type expected in the parameter, you can pass your object in". Part of the AsRef weirdness is just that Option::as_ref() and Result::as_ref() trip people up into thinking their part of that trait. Those also trip people up - myself included for a while.

  • @nulled7888
    @nulled7888 2 ปีที่แล้ว

    Thanks :)

  • @flyingsquirrel3271
    @flyingsquirrel3271 2 ปีที่แล้ว

    Thanks a lot, this really helped! Especially the last part. Now I understand why Borrow can be used in a real HashMap like that. Implementing Borrow implies that the borrowed Type is getting the same hash by convention. Makes sense!

  • @ianakotey
    @ianakotey 2 ปีที่แล้ว

    AsRef is to be used for cheap conversions. Basically cheap object to pointer, or pointer to pointer conversions. Borrow is to be used to obtain some reference to an owned type

  • @benjahnz
    @benjahnz 2 ปีที่แล้ว

    Excellent job explaining a tricky subject. Nice simple examples and no ego. Thanks dude.

  • @rl1111rl
    @rl1111rl 2 ปีที่แล้ว

    thank you! Can you show us integer references using a visual diagram? I'd like to see what these variables look like in memory. e.g. let mut x = 10; and have two other variables y and z reference it. could you update x, and would y and z update as well because they are pointing to the same memory address??

    • @danlogs
      @danlogs ปีที่แล้ว

      I'm not sure I'm too confident in my artistic skills to draw you a diagram, but I'll try to explain: (Example #1) 𝚏𝚗 𝚖𝚊𝚒𝚗() { 𝚕𝚎𝚝 𝚖𝚞𝚝 𝚡 = 𝟷0; 𝚕𝚎𝚝 𝚢 = &𝚡; 𝚕𝚎𝚝 𝚣 = &𝚡; // 𝚙𝚛𝚒𝚗𝚝 𝚊𝚕𝚕 𝚟𝚊𝚛𝚜 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("𝚡: {}, 𝚢: {}, 𝚣: {}", 𝚡, 𝚢, 𝚣); // 𝚌𝚑𝚊𝚗𝚐𝚎 𝚡 𝚡 = 𝟸0; // 𝚙𝚛𝚒𝚗𝚝 𝚊𝚕𝚕 𝚟𝚊𝚛𝚜 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("𝚡: {}, 𝚢: {}, 𝚣: {}", 𝚡, 𝚢, 𝚣); } (play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c684bf88870bd0761c27385c9a3b15ec) ^^^ this doesn't compile, as we cannot assign to 𝚡 after it's bene immutably borrowed. After this, you may think - Oh, that's ok, we can just make the references mutable! BUT... (Example #2) 𝚏𝚗 𝚖𝚊𝚒𝚗() { 𝚕𝚎𝚝 𝚖𝚞𝚝 𝚡 = 𝟷0; 𝚕𝚎𝚝 𝚢 = &𝚖𝚞𝚝 𝚡; 𝚕𝚎𝚝 𝚣 = &𝚖𝚞𝚝 𝚡; // 𝚙𝚛𝚒𝚗𝚝 𝚊𝚕𝚕 𝚟𝚊𝚛𝚜 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("𝚡: {}, 𝚢: {}, 𝚣: {}", 𝚡, 𝚢, 𝚣); // 𝚌𝚑𝚊𝚗𝚐𝚎 𝚡 𝚡 = 𝟸0; // 𝚙𝚛𝚒𝚗𝚝 𝚊𝚕𝚕 𝚟𝚊𝚛𝚜 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("𝚡: {}, 𝚢: {}, 𝚣: {}", 𝚡, 𝚢, 𝚣); } (play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a27ce1c125a55b2387ddd5986398e106) ^^^ also does not compile, because we cannot mutably borrow 𝚡 twice. (Working Example) 𝚏𝚗 𝚖𝚊𝚒𝚗() { 𝚕𝚎𝚝 𝚖𝚞𝚝 𝚡 = 𝟷0; 𝚕𝚎𝚝 𝚢 = &𝚖𝚞𝚝 𝚡; // 𝚙𝚛𝚒𝚗𝚝𝚒𝚗𝚐 𝚘𝚗𝚕𝚢 𝚢 '𝚌𝚊𝚞𝚜𝚎 𝚡 𝚠𝚊𝚜 𝚊𝚕𝚛𝚎𝚊𝚍𝚢 𝚖𝚞𝚝𝚊𝚋𝚕𝚢 𝚋𝚘𝚛𝚛𝚘𝚠𝚎𝚍, // 𝚊𝚗𝚍 𝚒𝚝 𝚝𝚊𝚔𝚎𝚜 𝚊𝚗 𝚒𝚖𝚖𝚞𝚝𝚊𝚋𝚕𝚎 𝚋𝚘𝚛𝚛𝚘𝚠 𝚘𝚏 𝚡 𝚝𝚘 𝚙𝚛𝚒𝚗𝚝 𝚒𝚝 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("𝚢: {}", 𝚢); *𝚢 = 𝟸0; // 𝚊𝚜 𝚢 𝚒𝚜 𝚗𝚘 𝚕𝚘𝚗𝚐𝚎𝚛 𝚞𝚜𝚎𝚍, 𝚠𝚎 𝚌𝚊𝚗 𝚙𝚛𝚒𝚗𝚝 𝚡 𝚙𝚛𝚒𝚗𝚝𝚕𝚗!("𝚡: {}", 𝚡); // 𝚘𝚞𝚝𝚙𝚞𝚝: // 𝚢: 𝟷0 // 𝚡: 𝟸0 } (play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=94aec871dd2770874e9210212c90e64b). For more details on this stuff, I'd recommend checking out this video if you haven't already: th-cam.com/video/iMJtA5i335Q/w-d-xo.html

  • @angelbythewings
    @angelbythewings 2 ปีที่แล้ว

    wow this is the first time i have truly understood closures in rust.

  • @Roastercode
    @Roastercode 2 ปีที่แล้ว

    Thank you for the effort. Please increase the resolution on the code screen. Thx!!!

    • @danlogs
      @danlogs 2 ปีที่แล้ว

      It took me a while, but I fixed it on later videos - Thanks! (:

  • @jjjunkie
    @jjjunkie 2 ปีที่แล้ว

    Great job at keeping to the point - most other youtubers introduce a hundred other concepts that complicate the topic being explained.