3 ms·
> Is Rust basically based on unique_ptr? Rust is based on ownership and statically checked move semantics (by default though can be opted out). So each item ha
by masklinn 6y ago
> Is Rust basically based on unique_ptr?
Rust is based on ownership and statically checked move semantics (by default though can be opted out). So each item has a single owner (which is why Rust deals very badly with graphs, and more generally any situation where ownership is unclear) and the compiler will prevent you from using a moved object (unlike C++).
Separately it has a smart pointer which is the dual of unique_ptr (Box), with the guarantee noted above:
let b = Box::new(1);
drop(b);
println!("{}", b);
will not compile because the second line moves the box, after which it can't be used because it's been removed entirely from this scope.
- wnoise 6y ago> which is why Rust deals very badly with graphs, and more generally any situation where ownership is unclear To be fair, so do 90+% of programmers. Much of rust's benefit in safe code is training programmers to avoid code like that where possible, and spreading design patterns that avoid it.