Re:Rust vs. Go
by saosebastiao on Thursday January 19, 2017 @01:13AM
(#13433492)
Can you explain the purpose of your '_unconstructable'?
[ Parent
| on HN ]
Re:Rust vs. Go
by lordnaikon on Thursday January 19, 2017 @05:04AM
(#13434535)
Sure. It is a private field(no pub) preventing you from constructing that type with a literal. It is of type "unit" '()' so it does not add up space for the type. "unit" has only one value that makes it "zero-sized". because i did not supply an "constructor" to that type it is not constructable outside the module and can only created by types in the scope of the enclosing module. Its more or less a private constructor known in C++/Java ... etc.
Steve Klabnik has a more complete write up regarding this http://words.steveklabnik.com/structure-literals-vs-construc...
If a struct is public, and all its members are public, you can just create a new instance of the struct with braces (in that case, it would be `OpenSocket { data: 12 }` - or whatever value you like), not what is necessarily correct. By having a hidden zero sized struct member, you need to use the library's api to construct them.