Writing Unsafe Rust

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

ความคิดเห็น • 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.

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

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

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

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

    I love the vibe of the intro!

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

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

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

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

    Amazing as always Bogdan.Great job!

  • @Nadim-qk4sh
    @Nadim-qk4sh 15 วันที่ผ่านมา

    intro go crazy on this one

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

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

  • @PravinKumar-lo8em
    @PravinKumar-lo8em 3 ปีที่แล้ว +3

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

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

    Hope we can get async rust with tokio tutorial soon!

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

    14:53 I really liked that!

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

    Rustie quarter life crisis 🤘🤘

  • @Mustafa-099
    @Mustafa-099 ปีที่แล้ว +1

    The intro got me lmao

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

      Let's get freakin' rusty

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

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

  • @lidiyapshonyak4249
    @lidiyapshonyak4249 3 ปีที่แล้ว

    Yesss love this!! less get rustyyy boi

  • @BlackVelvet854
    @BlackVelvet854 3 ปีที่แล้ว

    Great stuff !

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

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

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

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

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

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

    Someone tagged CrowdStrike CEO here please xXD

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

    wa wa weewa!

  • @bayezidmahmud5364
    @bayezidmahmud5364 3 ปีที่แล้ว

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

  • @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++.