News for hackers. Stuff that matters.
Re:From Zero to Main(): Bare Metal Rust by chubs on Tuesday December 17, 2019 @10:10PM (#21821420)
So is it the case that you only need 'unsafe' for some of your codebase where you're eg bit-banging, or using peripherals, or whatever - but the majority of your logic is running in normal 'safe' mode?
Re:From Zero to Main(): Bare Metal Rust by PudgePacket on Tuesday December 17, 2019 @10:58PM (#21821639)
Some amount of unsafe is impossible to avoid for doing certain things. Rust unsafe allows developers to focus their memory auditing efforts, rather than existing languages where _everywhere_ must be checked.

Here's an example. The Rust standard library has unsafe code to do things like allocate memory and read from files. However, it provides a safe abstraction that my code can use "safely" and be confident I won't encounter any memory errors.

Or if you're writing some kind of concurrent data structure, you want to be doing pointer and memory shenanigans for efficiency, but you'd make a safe API for consumers of the data structure.

I think a lot of people are scared initially seeing something like "unsafe". It's kind of equivalent to just regular C/C++ land... It doesn't automatically mean "The program will now eat your memory".

Re:From Zero to Main(): Bare Metal Rust by littlestymaar on Tuesday December 17, 2019 @10:43PM (#21821569)
That's right.

For instance, in the redox-os kernel, there is less than 100 places where unsafe is needed : https://doc.redox-os.org/book/introduction/unsafes.html.

Re:From Zero to Main(): Bare Metal Rust by mlindner on Tuesday December 17, 2019 @10:53PM (#21821610)
And to be more specific you'd ideally write an interface implementation that does that bit banging for you such that you call those functions from your safe code.