Hacker News new | ask | show | jobs
by barsonme 3298 days ago
If you—like me—were interested in Diesel ORM's zero sized types thing, here's a pretty decent explanation: https://np.reddit.com/r/rust/comments/3ur9co/announcing_dies...

edit: Go also has zero-sized types (struct{}), so I wonder if this is also possible? Probably not, I don't think, since the compiler doesn't see through interfaces.

2 comments

If you're interested in more of this, Sean, the author of Diesel, is giving a talk @ RustConf in August (http://rustconf.com/program.html#sean) which will probably cover these tricks in more depth :)

[Talks will be recorded, but also tickets are on sale right now if you want to be there in person!]

> Go also has zero-sized types (struct{}), so I wonder if this is also possible?

No. It specifically uses Rust's generics system, and the fact that generics are monomorphized at compile time, whereas Go interfaces are not.

C++ templates can be used in similar ways.

Yes, but differently; C/C++ explicitly prohibit zero-sized types due to object identity.
To clarify: C says it's UB, C++ rounds up to 1.