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
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).
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.)
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.
@@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 ☺
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++.
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
Never thought I would be remotely consuming this much Rust content in a day, but everything changed after I came across this channel.
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
Good points!
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).
4:21 Directly referring to addresses like this is definitely useful in embedded programming so it’s not a silly example in that context.
Your videos are awesome man.
Thank you for all the work you do for the community!
This video is almost identical with The Rust Programming language book. And well described.
I just enjoy the way u add references to ur healthy humour in a very safe way 👌
I love the vibe of the intro!
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.)
Next, I would like to see a small project which connect these concepts....
Amazing as always Bogdan.Great job!
Fantastic effort.. Makes it very easy for us !!! Thanks Bogden.. LGR !!!
Hope we can get async rust with tokio tutorial soon!
intro go crazy on this one
Reverse psychology, very unsafe way to convince me but it worked
14:53 I really liked that!
It seems that split_at_mut now is an existing function in latest stable rust release
The intro got me lmao
Let's get freakin' rusty
Yesss love this!! less get rustyyy boi
You already be knowin
Great stuff !
Thanks my guy :)
Rustie quarter life crisis 🤘🤘
Tfw daddy pike lets you have generics
AWESOME
unsafe rust vs C ... ??? what would happen ?
is unsafe rust powerful as C ?
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.
@@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 ☺
Am I ready to make a Krabby Patty now Mr. Krabs?
unsafe in rust means: Hey compiler, i know what i'm doin', f*ck off and don't error to me.
Hey There! Love your content! How about opening a discord server?!
Maybe one day!
wa wa weewa!
I like!
Someone tagged CrowdStrike CEO here please xXD
+sub, workis
lets get greaking rusty lol
is it just me or does the thumbnail gets dumber 😑
This is not even my final form
@@letsgetrusty das gud
haha.. nice thumb nail!
if i want to use unsafe then it's better to use c or c++ why rust???
Use the tool that suit u better .
Usually unsafe rust is used safely when the compiler doesn't understand something thats safe .
How is this even related
@@----__---
If he want to use c he can use c.
You still have access to benefits of rust like crates etc
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++.