Re:Tour of Rust
by umanwizard on Sunday July 12, 2020 @09:01AM
(#23811004)
AFAICT, Box has exactly the same semantics as C++‘s unique_ptr.
Where it can have the same semantics, yes. But if you look at the details, not exactly. For example Box is not nullable, but a not-nullable C++ equivalent is hard to do given the rest of the language.
Re:Tour of Rust
by umanwizard on Sunday July 12, 2020 @11:26AM
(#23812043)
Good point on the nullability; yes, that is indeed different from std::unique_ptr.
A pointer and a heap allocation are the obvious choice for implementing this, but the semantics are notably different than just being a pointer. Rust also does have pointer types which represent true pointers.