3 ms·
> The unique safety features of Rus are all about memory safety, which is not something you have to worry about at all in Python Rust gets safety with its owne
by andrewxdiamond 4y ago
> The unique safety features of Rus are all about memory safety, which is not something you have to worry about at all in Python
Rust gets safety with its ownership system. The ownership system brings strong guarantees around who is mutating / reading any given object.
Python has uncontrolled ownership. Any function can generally mutate / store any variable you pass in. This can definitely cause bugs if a rouge function starts modifying input.
Rust makes this impossible without the mutation “permission” being part of the method signature. Strong ownership controls force functions to be extremely explicit with their intentions
- rustinquisition 4y ago
- deleted 4y ago[deleted]
- Too 4y agoFor those not familiar with ownership concepts, it does apply to many things beyond just memory management. Most obvious example of this is file handles. In python you have to close() them or scope within a context manager to auto close when the block exits. If you need more complex logic around, such as transfer the handle into another function, the context manager is no longer sufficient and you quickly loose track of who should call close(), is it the caller or the callee. Rust keeps track of this, no matter how deep you twist your logic and it does so for every variable, no context manager blocks required.
- cztomsik 4y agowrong, rust is about exclusive ptr access, nothing more. you cannot do ReadOnly<T> in rust.
- pg999w 4y agoWhy not? Isn't that &T like a read only wrapper of T?
- cztomsik 4y agotry to do ReadOnly<T> yourself, and then put Cell into it, or RwLock, or Mutex, or Atomic, or crossbeam channel, ... it LOOKS like it's possible but it can be broken easily. again, because rust is not really about (i)mutability, it's about mem-safety - and all of those can be safely mutated with &T