Writing Unsafe Rust

Поділитися
Вставка

КОМЕНТАРІ • 52

  • @letsgetrusty
    @letsgetrusty  3 роки тому +7

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

  • @obitorasu1760
    @obitorasu1760 3 роки тому +89

    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 3 роки тому +54

    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  3 роки тому +6

      Good points!

    • @DipsAndPushups
      @DipsAndPushups Рік тому +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).

  • @Banikan
    @Banikan Рік тому +3

    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 3 роки тому +7

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

  • @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 👌

  • @rootkill1581
    @rootkill1581 3 роки тому +4

    I love the vibe of the intro!

  • @oconnor663
    @oconnor663 2 роки тому +8

    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. UA-cam seems to delete my comment when I do that.)

  • @PravinKumar-lo8em
    @PravinKumar-lo8em 3 роки тому +3

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

  • @boqnbalev2848
    @boqnbalev2848 3 роки тому +3

    Amazing as always Bogdan.Great job!

  • @rohitcr6839
    @rohitcr6839 6 місяців тому

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

  • @scotty3024
    @scotty3024 3 роки тому +2

    Hope we can get async rust with tokio tutorial soon!

  • @Nadim-qk4sh
    @Nadim-qk4sh 20 днів тому

    intro go crazy on this one

  • @pathfinder750
    @pathfinder750 3 роки тому +4

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

  • @eltama1299
    @eltama1299 2 роки тому

    14:53 I really liked that!

  • @alexdai_
    @alexdai_ Рік тому

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

  • @Mustafa-099
    @Mustafa-099 Рік тому +1

    The intro got me lmao

    • @hcn6708
      @hcn6708 5 місяців тому

      Let's get freakin' rusty

  • @lidiyapshonyak4249
    @lidiyapshonyak4249 3 роки тому

    Yesss love this!! less get rustyyy boi

  • @BlackVelvet854
    @BlackVelvet854 3 роки тому

    Great stuff !

  • @GolangDojo
    @GolangDojo 3 роки тому +2

    Rustie quarter life crisis 🤘🤘

  • @ramanShariati
    @ramanShariati 2 роки тому

    AWESOME

  • @monirahmadi9605
    @monirahmadi9605 3 роки тому +3

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

    • @KohuGaly
      @KohuGaly 3 роки тому +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 3 роки тому +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 ☺

  • @NottNott
    @NottNott 2 роки тому

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

  • @denizsincar29
    @denizsincar29 2 місяці тому

    unsafe in rust means: Hey compiler, i know what i'm doin', f*ck off and don't error to me.

  • @bayezidmahmud5364
    @bayezidmahmud5364 3 роки тому

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

  • @shravanshetty347
    @shravanshetty347 3 роки тому +1

    wa wa weewa!

  • @1234fewgfwe
    @1234fewgfwe 4 місяці тому

    Someone tagged CrowdStrike CEO here please xXD

  • @kunalkunal63
    @kunalkunal63 2 роки тому

    +sub, workis

  • @1234fewgfwe
    @1234fewgfwe 4 місяці тому

    lets get greaking rusty lol

  • @gilfoylefromchrissdiscords9502
    @gilfoylefromchrissdiscords9502 3 роки тому +6

    is it just me or does the thumbnail gets dumber 😑

  • @ksnyou
    @ksnyou 3 роки тому

    haha.. nice thumb nail!

  • @techlifejournal
    @techlifejournal 3 роки тому

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

    • @xrafter
      @xrafter 3 роки тому +1

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

    • @----__---
      @----__--- 3 роки тому

      How is this even related

    • @xrafter
      @xrafter 3 роки тому

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

    • @kritagyagupta9356
      @kritagyagupta9356 3 роки тому +1

      You still have access to benefits of rust like crates etc

    • @ramesses_ii
      @ramesses_ii 3 роки тому +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++.