News for hackers. Stuff that matters.
Re:Rust via its Core Values by Odin78 on Monday April 04, 2016 @03:51AM (#11420105)
Is Rusts concept of ownership any different from C++ unique_ptrs?
Re:Rust via its Core Values by steveklabnik on Monday April 04, 2016 @02:40PM (#11424244)
As an example, here are two roughly equivalent programs. First Rust:

    let x = Box::new(5);
    let y = x;
    println!("{}", x);
Now C++:

    unique_ptr<int> x(new int(5));

    auto y = std::move(x);

    cout << *x << endl;
(I'm being a bit sloppy with namespaces, and both need a main(), but you get the idea)

Here, the C++ will compile and (probably) segfault, as x is nullptr after the move. The Rust will fail at compile time, with "use of moved value."

Basically, a (possibly over-)generalization of the situation is "Rust is move by default and captures errors at compile time, C++ is not move by default and cannot statically prevent as many errors as Rust can."

Re:Rust via its Core Values by kibwen on Monday April 04, 2016 @03:58AM (#11420128)
It's not identical (Rust statically enforces a lot more than C++ does, move semantics are opt-out rather than opt-in, there's no such thing as move constructors in Rust, etc.), but if you understand unique_ptr then you'll understand Rust's concept of ownership.