News for hackers. Stuff that matters.
Re:Ownership and Borrowing in D by Scarbutt on Monday July 15, 2019 @11:56PM (#20447354)
If you don't mind, I'm curious about what "partially move structs" are? Structs have always feel like a chore to me, complicating things more when compared to maps in dynamic langs. Maybe Rust has something for dealing with the "explosion of types" issue and dealing with partial information in structs that I don't know about. Skimming through the rust book looks like Option<T> is the solution to missing data in structs.
Re:Ownership and Borrowing in D by coder543 on Tuesday July 16, 2019 @12:08AM (#20447388)
Partially moved just means that the compiler tracks which fields have been “moved out” of the struct and prevents you from either accessing those fields or attempting to reuse the partially moved struct as if it were still a whole struct, since it is no longer whole... it has given up some of its members, conceptually.

In the article linked by this discussion, the author specifically mentions how fields can’t be moved out in D’s implementation.

Option is the correct approach for dealing with information that might be missing, but that’s not really related to partially moved structs.

Structs document what is available in a given value, to both the compiler and to you. If that’s not convincing, then I’m not going to try more here... it’s off topic. But I will say you can use maps in Rust or other statically typed languages. They’re just not meant to be an alternative to well-defined structs.

Re:Ownership and Borrowing in D by didibus on Tuesday July 16, 2019 @01:37AM (#20447715)
Can Rust now handle partial move semantics on structs? I remember reading it couldn't do it before, and there were threads about how you should make small structs because of that, or that you should not use methods, because they take ownership of the full struct and not just the fields that they actually use, etc.
Re:Ownership and Borrowing in D by littlestymaar on Tuesday July 16, 2019 @03:33AM (#20448180)
It can, with the big caveat that it only works well if you don't cross a function boundary.
Re:Ownership and Borrowing in D by didibus on Tuesday July 16, 2019 @12:32PM (#20451564)
Ah, so passing a struct as an argument to a function will still take ownership or borrow the entire struct?
Re:Ownership and Borrowing in D by Scarbutt on Tuesday July 16, 2019 @12:34AM (#20447491)
Sure, my intention was not to get in a dynamic vs static lang argument, when seeing "partial moved structs" and "ergonomics" in the same sentence my mind jump to think that there is something Rust that can make it feel closer to a dynamic lang regarding types ;) Thanks.
Re:Ownership and Borrowing in D by didibus on Tuesday July 16, 2019 @02:01AM (#20447810)
Rust doesn't have anything for that. Partial move means that if a function only really need to access one field on the struct, it would only take ownership of that field, even though it took the full struct as an argument. So two functions could have ownership of different fields of the struct at the same time.

One thing with Rust is that it is really focused on performance and safety. It also cares about ergonomics, but not over performance and safety. Unfortunately, type explosion does make for faster code that can be validated more easily for safety by the compiler. That said, Rust has good support for vectors, those are used a lot, but are homogeneous. It also supports tuples with nice literal syntax and pattern matching on them. While it favours structs over maps, they are pretty lightweight compared to objects, so very small syntax to define them, you can create one out of another, and have a nice literal syntax to create them. Still, this is not the magical world of dynamic data-structures, so don't try and think you can just map/reduce over your structs and tuples, compose and restructure them freely, print out their content, or merge and split them, etc..

Re:Ownership and Borrowing in D by eternalban on Tuesday July 16, 2019 @05:07AM (#20448545)
So the only thing that is "moving" is the ownership of elements of a structure.

It seems "partial move" actually means "partial transfer".

Re:Ownership and Borrowing in D by didibus on Tuesday July 16, 2019 @12:48PM (#20451691)
> So the only thing that is "moving" is the ownership of elements of a structure.

Yup

In rust, you can move, copy or borrow a value.

Move - means that the responsibility of freeing the allocated memory is moving to someone else. Rust says the ownership has moved.

Copy - means that the full value is copied, and a copy is passed, thus now you have two instances of the value, and each can act independently.

Borrow - means that the access permissions to the value are temporarily transferred to something else, but will come back when done, and the responsibility of freeing the memory is still up to the owner (lender).

That's why it is called "partial move", cause it's using Rust's terminology. Transfer isn't in the Rust lexicon, so it wouldn't be as appropriate.

Re:Ownership and Borrowing in D by WalterBright on Tuesday July 16, 2019 @01:59AM (#20447800)
There are no plans at the moment for D to implement partial struct moving.