News for hackers. Stuff that matters.
Re:You can't Rust that by phkahler on Saturday March 31, 2018 @07:19PM (#16725693)
If pointers are useless, how do you create complex data structures. In a C++ program I have a struct that is nothing but 5 pointers (4 now since 2 can be stored as their XOR). I'm starting to wonder about this Rust thing that's been sounding so awesome...
Re:You can't Rust that by gpm on Saturday March 31, 2018 @08:31PM (#16725980)
Pointers aren't useless... things don't move if you don't tell them to. The compiler can statically guarantee they don't move while you have a pointer to them (via references/lifetimes) or with unsafe code you can just tell the compiler that "I checked and I don't move this thing". I've had plenty of rust datastructures that are just a collection of pointers.

The distinction I guess is that in rust you can move things assuming you have no references to them, while in c++ you can't really (I mean, move constructors, but that's really a fancy copy where the initial thing still exists in some form). And moving things is pretty normal - as is taking pointers to them - just not at the same time.

Re:You can't Rust that by jay-anderson on Sunday April 01, 2018 @02:18AM (#16727019)
> things don't move if you don't tell them to

This is something I've struggled a bit with when playing with Rust. I've had a hard time understanding whether I'm telling the compiler to move or copy. In other words I need to understand better what I'm telling it to do (I probably just need to buckle down and study the new book in this area better). It wasn't immediately obvious to me when I last played with it.

Re:You can't Rust that by masklinn on Sunday April 01, 2018 @07:27AM (#16727748)
> I've had a hard time understanding whether I'm telling the compiler to move or copy. In other words I need to understand better what I'm telling it to do

You're not telling it anything, in Rust copy v move is a type-level concern: either the type is "move" (the default) or it's "copy".

There is no difference at the machine-level either (it's semantically doing a memcpy either way, Rust has no move ctor v copy ctor and its move semantics are somewhat different than C++), the difference is whether the compiler will let you use the source object afterwards.

Incidentally, I believe you're not really "telling the compiler to move or copy" in C++ either, you're only suggesting that it can move and whether it actually does so depends on the type's ctors and IIRC the receiver's overloads: std::move on a type which can't be moved or with a target which doesn't care does not do anything.

Re:You can't Rust that by steveklabnik on Sunday April 01, 2018 @02:53AM (#16727110)
It depends on the type, not what you say. Copy types copy, other types move.
Re:You can't Rust that by smaddox on Sunday April 01, 2018 @10:56AM (#16728587)
Box (an owned pointer to heap-allocated struct), Rc (reference-counted heap-allocated shared struct), and Arc (atomicly reference-counted heap-allocated shared struct) cover any cases that indicies into an array (or other data structure) don't.
Re:You can't Rust that by pcwalton on Saturday March 31, 2018 @08:05PM (#16725862)
Unique pointers or reference counted pointers.