Writing Unsafe Rust

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

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

  • @letsgetrusty
    @letsgetrusty  2 года назад +7

    📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet

  • @obitorasu1760
    @obitorasu1760 2 года назад +86

    Never thought I would be remotely consuming this much Rust content in a day, but everything changed after I came across this channel.

  • @ramesses_ii
    @ramesses_ii 2 года назад +52

    I think there's a lot of misconception concerning unsafe Rust. Using unsafe Rust does not turn off ALL the safety guarantees of Rust. It allows you to perform some tasks and operations that the compiler forbids in safe Rust.
    I find a lot of arguments that if I'm going to write unsafe Rust, I might as well use C/C++. While this is not a C++ vs Rust post (and frankly that argument is stupid). All of C++ code is inherently unsafe while unsafe Rust code is safely nested in the unsafe blocks and the rest of the code is safe with all the wonderful safety guarantees.
    This aids easy identification of bugs and issues in your code and alerts any users to potential hotspots in the codebase.
    You would rarely need to write unsafe Rust even in a large professional code base. And I think unsafe Rust exists for those coming from C/C++ as well as development on embedded devices and OSs where bare metal programming may become necessary

    • @letsgetrusty
      @letsgetrusty  2 года назад +6

      Good points!

    • @student99bg
      @student99bg Год назад +1

      Unsafe is necessary for low level programming. However, unlike in C there are safe alternatives of writing code and unlike in C++ the safe way of doing things is the easier, default way of doing things. You need less hustle in order to write safe Rust than to write unsafe Rust. It is the exact opposite with C++ (and especially with C where if you want to write safe code you need to create a lot of wrappers and then be very disciplined about how you use them).

  • @rohitcr6839
    @rohitcr6839 3 месяца назад

    Fantastic effort.. Makes it very easy for us !!! Thanks Bogden.. LGR !!!

  • @rootkill1581
    @rootkill1581 2 года назад +4

    I love the vibe of the intro!

  • @Banikan
    @Banikan 10 месяцев назад +1

    4:21 Directly referring to addresses like this is definitely useful in embedded programming so it’s not a silly example in that context.

  • @jonathancamarena3117
    @jonathancamarena3117 2 года назад +7

    Your videos are awesome man.
    Thank you for all the work you do for the community!

  • @oconnor663
    @oconnor663 Год назад +7

    The raw pointers example at 4:59 fails Miri. I think the issue is that the temporary `&mut num` created on line 5 ends the shared borrow from line 4 and invalidates the *const pointer that's derived from it. You can see the Miri error if you copy the code to the Rust Playground and select Miri under Tools. (Apologies for not just including a link. RUclips seems to delete my comment when I do that.)

  • @kobruh9642
    @kobruh9642 Год назад +1

    This video is almost identical with The Rust Programming language book. And well described.

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

    I just enjoy the way u add references to ur healthy humour in a very safe way 👌

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

    Amazing as always Bogdan.Great job!

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

    Hope we can get async rust with tokio tutorial soon!

  • @PravinKumar-lo8em
    @PravinKumar-lo8em 2 года назад +3

    Next, I would like to see a small project which connect these concepts....

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

    Reverse psychology, very unsafe way to convince me but it worked

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

    14:53 I really liked that!

  • @Mustafa-099
    @Mustafa-099 Год назад +1

    The intro got me lmao

    • @hcn6708
      @hcn6708 2 месяца назад

      Let's get freakin' rusty

  • @alexdai_
    @alexdai_ 11 месяцев назад

    It seems that split_at_mut now is an existing function in latest stable rust release

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

    Great stuff !

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

    Yesss love this!! less get rustyyy boi

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

    Rustie quarter life crisis 🤘🤘

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

    AWESOME

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

    unsafe rust vs C ... ??? what would happen ?
    is unsafe rust powerful as C ?

    • @KohuGaly
      @KohuGaly 2 года назад +5

      Yes, unsafe rust is as powerful as C. Pretty much any language that can dereference pointers and cast types arbitrarily (including function pointers) is as powerful as C.

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

      @@KohuGaly thanks bro ,,, i`m learning but i`m really concern which area i wanna play ...
      OS_dev ,,, web-assembly machine learning ?
      i`m interested in artificial intelligence either or "internet of things" ... i don't know ☺

  • @jayleejw1801
    @jayleejw1801 Месяц назад

    Someone tagged CrowdStrike CEO here please xXD

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

    Hey There! Love your content! How about opening a discord server?!

  • @NottNott
    @NottNott Год назад

    Am I ready to make a Krabby Patty now Mr. Krabs?

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

    wa wa weewa!

  • @jayleejw1801
    @jayleejw1801 Месяц назад

    lets get greaking rusty lol

  • @kunalkunal63
    @kunalkunal63 Год назад

    +sub, workis

  • @gilfoylefromchrissdiscords9502
    @gilfoylefromchrissdiscords9502 2 года назад +6

    is it just me or does the thumbnail gets dumber 😑

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

    if i want to use unsafe then it's better to use c or c++ why rust???

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

      Use the tool that suit u better .
      Usually unsafe rust is used safely when the compiler doesn't understand something thats safe .

    • @----__---
      @----__--- 2 года назад

      How is this even related

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

      @@----__---
      If he want to use c he can use c.

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

      You still have access to benefits of rust like crates etc

    • @ramesses_ii
      @ramesses_ii 2 года назад +5

      Because the unsafe block helps you islolate and identify potential issues in your code. As stated in the video, it doesn't turn off all the safe guarantees of rust like the borrow checker or bounds checking.
      If your code has issues particularly due to memory, it's easier to identify the source than c/c++.

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

    haha.. nice thumb nail!