Rust: RefCell

แชร์
ฝัง

ความคิดเห็น • 13

  • @mx-5driver406
    @mx-5driver406 ปีที่แล้ว +11

    Also worth mentioning is that it's almost always better to use Cell instead of RefCell for Copy types (like i32). This avoids the overhead of the runtime borrow check and can never cause a panic.

  • @peterthecoderd.1210
    @peterthecoderd.1210 ปีที่แล้ว +3

    Arc, Rc, Box and Cell/RefCell are the most confusing aspects, so far, of my learning Rust. I will have to re-watch your videos a few times, in hopes of grasping these concepts. Thanks!

  • @npf21
    @npf21 ปีที่แล้ว +1

    Just wanted to mention you say the the correct definition for Rc but the text is incorrect it should be allow "immutable" checks at compile time @4:09

  • @joeystenbeck6697
    @joeystenbeck6697 ปีที่แล้ว +2

    I've been confused by this but this video explains RefCell/RefMut so clearly! Thanks!

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

    Just worked through this chapter in the rust programming book today, perfect time for your video to appear in my feed for a recap!

  • @ovidiu_nl
    @ovidiu_nl ปีที่แล้ว +3

    Unsafe Rust gives you a few "superpowers", but playing jedi mind tricks with the borrow checker is not one of them. The borrow checker will still check your code. :D
    As far as I remember these types with internal mutability all ultimately use UnsafeCell as a building block. The compiler gives UnsafeCell some special treatment.

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

      Nice video, btw 👍
      I liked your mock example.

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

      Agreed; the Rustonomicon is pretty clear that you still have to obey the borrowing rules, in some form.

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

    this was helpful. much appreciated!

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

    thank you ❤

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

    Why don't just change the `trait Messenger` signature to `mut self` ?

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

      because it just checking if it's sending correct message or not
      in the real world example it will not take mutable reference of a string
      because we just want send that message via email or number , so we are not storing it
      and we can't really change our implementation just for test

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

    So why would RefCell be unsafe if it's implemented by the Rust devs? The entire compiler could have bugs that make Rust code fail, so why not give RefCell the same guarantee and call it a safe intrinsic?