Rust: Store Data on the Heap with Box

Поделиться
HTML-код
  • Опубликовано: 15 дек 2024

Комментарии • 10

  • @bbkr2063
    @bbkr2063 6 месяцев назад +1

    When reaching Box lesson I got epiphany that String is just Box::new("foo"). While not being exactly correct (String object is more feature rich than slice) it helped me to understand why compiler is not complaining about struct size when I define "Struct{ x: String }". Somehow suddenly this heap/stack concept "clicked" in my mind.

  • @yankee-in-london
    @yankee-in-london 2 года назад +3

    is it possible to use `.into()` instead of the new constructor? Feels like that would make it look more intuitive.

    • @hezuikn
      @hezuikn 2 года назад +2

      ah yes putting things into boxes

  • @hiraginoyuki
    @hiraginoyuki 2 года назад +3

    isn't it Deref(erence)

    • @TheDevMethod
      @TheDevMethod  2 года назад +1

      Yes. I meant to say Deref and not Defer

  • @MohammadRajablooloverajabloo
    @MohammadRajablooloverajabloo 2 года назад +3

    I have checked. the Box did not implement Defer, it's trait Deref that you mean.

    • @TheDevMethod
      @TheDevMethod  2 года назад +1

      Thank you for the correction!

    • @bobby9568
      @bobby9568 2 года назад

      @@TheDevMethod Will it still be memory safe?

  • @hezuikn
    @hezuikn 2 года назад

    oh boi i cant wait to see what this new trait "Defer" does
    deref_move want

    • @TheDevMethod
      @TheDevMethod  2 года назад +3

      I mean to say Deref and not Defer.