"More control over memory than C" is nonsense. C allows you to do anything the machine's instruction set is capable of, all the way down to inline assembly.
Undefined behavior is a completely separate conversation. UB is necessary to output performant code. If dereferencing a null pointer were defined behavior, then the compiler would need to insert a check for every dereference, which would slow down your code.
> C allows you to do anything the machine's instruction set is capable of
Hum, no, unless you count inline asm, it simply doesn't.
And for more control over memory than C, Rust allows mapping high-level types into fixed memory, so the compiler can actually use the correct asm primitives and make your access fast. On C you either have to use a general purpose array abstraction or try to map your types over the memory and pray the compiler resolves all the UB the way you want. Most C developers do the later.
I have no idea what you're talking about with "general purpose array abstraction" and "map your types over the memory". A struct in C is just a fixed size chunk of memory where the fields have a fixed offset. Access is a simple memory read/write. An array in C is also just a chunk of memory, where subscripting is some simple pointer math. There is no UB involved. If you could give a concrete example of what you're talking about and why it's better in Rust than in C, that might be helpful.
Only if you use unsafe and even then three are restrictions. The general idea of rust is that it will only let you do things it can verify are safe otherwise it won't compile.
> Only if you use unsafe and even then three are restrictions.
I can't think of any. The borrow checker still checks your code but you can forge, twiddle, and cast pointers, there's really nothing you can't do that I can think of.
> In both unsafe functions and unsafe blocks, Rust will let you do three things that you normally can not do. Just three. Here they are:
> Access or update a static mutable variable.
Dereference a raw pointer.
Call unsafe functions. This is the most powerful ability.
That’s it. It’s important that unsafe does not, for example, ‘turn off the borrow checker’. Adding unsafe to some random Rust code doesn’t change its semantics, it won’t start accepting anything. But it will let you write things that do break some of the rules.
That doesn't change anything I said. Those unsafe functions include things like casting pointers. There's nothing you can't do through some composition of those 3 things.
I am not very familiar with Rust, but I thought it permits full control over memory?