Compiling playground v0.0.1 (/playground)
error: the `Self` constructor can only be used with tuple or unit structs
--> src/lib.rs:15:9
|
15 | Self // fails
| ^^^^
error: could not compile `playground` due to previous error
I stumbled upon it, when implementing mmtkvdb::storable::Storable for other unit structs than () and wanted to keep the implementations following the same schema in all cases.
I guess someone could stumble upon it when using macros. (Update: Something like this Playground, though I see it can be easily worked around.)
I don't really need this to work, but I found it curious.
To phrase it differently: I believe if Self is a valid constructor for unit structs, then it should also be a valid constructor for the unit struct, i.e. for ().
() is not the unit struct. It's not even a unit struct. It's not even a struct, because it's a tuple. It's not a UDT but a built-in type that happens to be unit because it's the product of 0 other types. Since it's not a UDT, its constructor is not named but derives from the constructor syntax for tuples.
Oh, I made a mistake. It's indeed not called the unit struct but the unit type. (see reference)
For convenience and historical reasons, the tuple type with no fields (()) is often called unit or the unit type. Its one value is also called unit or the unit value.
So agreed, it's not a struct, but it's still unit.
Anyway, I see the pattern now. Basically Self as constructor isn't allowed because it's unit but because Self replaces the name.