CAD97:
I feel like a better approach to the issue felt by the OP would be extending this idea and allowing complete elision of (named or tail) PhantomData
-typed fields in patterns and literals. The field would still exist, but you'd be permitted to skip mentioning it outside of the type definition. It doesn't get you all the way to being a unit struct, but it's most of the desirable properties.
An alternative formulation that might be more (or less) acceptable this made me think of is "anonymous fields":
struct Foo<T> {
id: u32,
_: PhantomData<T>,
}
let foo: Foo<String> { id: 123 }
The difference is there's less magic in the field type, but it would still need something, but perhaps just a Default bound, which might be useful outside of PhantomData
?
4 Likes