logoalt Hacker News

tialaramextoday at 3:21 AM1 replyview on HN

Which makes sense because you could (and indeed still will be able to do) write your own uninhabited types very easily in Rust and indeed they're optimised accordingly. Because Rust has user-defined sum types you could simply write a sum of nothing:

    enum MyNeverType {}
...and it's uninhabited, the same way you can write the product of nothing

    struct MyUnitType {}
... and its size is zero.

Replies

nextaccountictoday at 3:44 AM

Note, to be more clear, an enum with no variants has no values of that type (can't be constructed), and a struct with no fields has exactly one value of that type